実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
N 種類のビーンズが 1 粒ずつあります。 i 種類目のビーンズはおいしさが A_i で色が C_i です。ビーンズは混ぜられており、色でしか区別することができません。
あなたはビーンズの色を 1 つ選び、その色のビーンズをどれか 1 粒食べます。ビーンズの色をうまく選ぶことで、食べる可能性のあるビーンズのおいしさの最小値を最大化してください。
制約
- 1 \leq N \leq 2 \times 10^{5}
- 1 \leq A_i \leq 10^{9}
- 1 \leq C_i \leq 10^{9}
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 C_1 A_2 C_2 \vdots A_N C_N
出力
食べる可能性のあるビーンズのおいしさの最小値の最大値を整数として出力せよ。
入力例 1
4 100 1 20 5 30 5 40 1
出力例 1
40
同じ色のビーンズは互いに区別がつかないことに注意してください。
選ぶことができる色は 色 1 と 色 5 です。
- 色 1 のビーンズは 2 種類あり、美味しさはそれぞれ 100, 40 です。よって、色 1 を選んだときのおいしさの最小値は 40 です。
- 色 5 のビーンズは 2 種類あり、美味しさはそれぞれ 20, 30 です。よって、色 5 を選んだときのおいしさの最小値は 20 です。
おいしさの最小値を最大化するには 色 1 を選べばよいため、そのときの最小値である 40 を出力します。
入力例 2
10 68 3 17 2 99 2 92 4 82 4 10 3 100 2 78 1 3 1 35 4
出力例 2
35
Score: 250 points
Problem Statement
There are N types of beans, one bean of each type. The i-th type of bean has a deliciousness of A_i and a color of C_i. The beans are mixed and can only be distinguished by color.
You will choose one color of beans and eat one bean of that color. By selecting the optimal color, maximize the minimum possible deliciousness of the bean you eat.
Constraints
- 1 \leq N \leq 2 \times 10^{5}
- 1 \leq A_i \leq 10^{9}
- 1 \leq C_i \leq 10^{9}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 C_1 A_2 C_2 \vdots A_N C_N
Output
Print as an integer the maximum value of the minimum possible deliciousness of the bean you eat.
Sample Input 1
4 100 1 20 5 30 5 40 1
Sample Output 1
40
Note that beans of the same color cannot be distinguished from each other.
You can choose color 1 or color 5.
- There are two types of beans of color 1, with deliciousness of 100 and 40. Thus, the minimum deliciousness when choosing color 1 is 40.
- There are two types of beans of color 5, with deliciousness of 20 and 30. Thus, the minimum deliciousness when choosing color 5 is 20.
To maximize the minimum deliciousness, you should choose color 1, so print the minimum deliciousness in that case: 40.
Sample Input 2
10 68 3 17 2 99 2 92 4 82 4 10 3 100 2 78 1 3 1 35 4
Sample Output 2
35
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられるので、以下の条件を全て満たす整数 X の個数を 998244353 で割った余りを求めてください。
- N 桁の正整数である。
- X の各桁を上の位から順に X_1,X_2,\dots,X_N とする。このとき以下の条件を全て満たす。
- 全ての整数 1 \le i \le N に対して、 1 \le X_i \le 9
- 全ての整数 1 \le i \le N-1 に対して、 |X_i-X_{i+1}| \le 1
制約
- N は整数
- 2 \le N \le 10^6
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
4
出力例 1
203
4 桁の整数として、例えば 1111,1234,7878,6545 が問題文中の条件を満たします。
入力例 2
2
出力例 2
25
入力例 3
1000000
出力例 3
248860093
998244353 で割った余りを求めることに注意してください。
Score : 300 points
Problem Statement
Given an integer N, find the number of integers X that satisfy all of the following conditions, modulo 998244353.
- X is an N-digit positive integer.
- Let X_1,X_2,\dots,X_N be the digits of X from top to bottom. They satisfy all of the following:
- 1 \le X_i \le 9 for all integers 1 \le i \le N;
- |X_i-X_{i+1}| \le 1 for all integers 1 \le i \le N-1.
Constraints
- N is an integer.
- 2 \le N \le 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
4
Sample Output 1
203
Some of the 4-digit integers satisfying the conditions are 1111,1234,7878,6545.
Sample Input 2
2
Sample Output 2
25
Sample Input 3
1000000
Sample Output 3
248860093
Be sure to find the count modulo 998244353.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
AtCoder 国は無限に広がる直交座標の上にあります。
AtCoder 国には N 個の街があり、 1,2,\dots,N と番号が付けられています。街 i は地点 (x_i, y_i) にあり、2 つの異なる番号の街が同じ座標にあることはありません。
AtCoder 国には転移魔法(以下、魔法と表記)があります。魔法は整数の組 (a,b) によって識別されていて、地点 (x,y) にいるときに魔法 (a,b) を使うと (x+a,y+b) にワープすることができます。
すぬけ君は、任意の整数の組 (a,b) を選んで魔法 (a,b) を覚えることができる大魔術師です。また、すぬけ君は何種類でも魔法を覚えることができます。
魔法を使って街と街の間を移動したくなったすぬけ君は、全ての相異なる街の組 (i,j) について次の行動を取れるようにいくつかの魔法を覚えることにしました。
- 覚えた魔法のうち 1 種類の魔法のみ を選ぶ。その後、選んだ魔法 のみ を繰り返し使って街 i から 街 j に移動する。
すぬけ君が上の条件を満たすように魔法を覚えるとき、少なくとも何種類の魔法を覚えればよいですか?
制約
- 2 \leq N \leq 500
- 0 \leq x_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq y_i \leq 10^9 (1 \leq i \leq N)
- i \neq j ならば (x_i, y_i) \neq (x_j, y_j) である。
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 \vdots x_N y_N
出力
すぬけ君が覚える必要がある魔法の個数の最小値を出力せよ。
入力例 1
3 1 2 3 6 7 4
出力例 1
6
AtCoder 国の街の位置を図示したのが下の図です。(わかりやすさのために四隅の座標を表示しています。)
すぬけ君は次の 6 種類の魔法を覚えれば、すべての (i,j) (i \neq j) の組に対して街 i から 1 種類の魔法を 1 回使うことで街 j に着くことができるので条件を満たします。
- (2, 4)
- (-2, -4)
- (4, -2)
- (-4, 2)
- (-6, -2)
- (6, 2)
次の 6 種類の魔法も条件を満たします。このときすぬけ君は、すべての (i,j) (i \neq j) の組に対して街 i から 1 種類の魔法を 2 回使うことで街 j に着くことができます。
- (1, 2)
- (-1, -2)
- (2, -1)
- (-2, 1)
- (-3, -1)
- (3, 1)
条件を満たす魔法の組み合わせのうち 6 種類より少ないものは存在しないので、 6 を出力します。
入力例 2
3 1 2 2 2 4 2
出力例 2
2
次の 2 種類の魔法を覚えるのが最適です。
- (1, 0)
- (-1, 0)
入力例 3
4 0 0 0 1000000000 1000000000 0 1000000000 1000000000
出力例 3
8
Score : 400 points
Problem Statement
The Republic of AtCoder lies on a Cartesian coordinate plane.
It has N towns, numbered 1,2,\dots,N. Town i is at (x_i, y_i), and no two different towns are at the same coordinates.
There are teleportation spells in the nation. A spell is identified by a pair of integers (a,b), and casting a spell (a, b) at coordinates (x, y) teleports you to (x+a, y+b).
Snuke is a great magician who can learn the spell (a, b) for any pair of integers (a, b) of his choice. The number of spells he can learn is also unlimited.
To be able to travel between the towns using spells, he has decided to learn some number of spells so that it is possible to do the following for every pair of different towns (i, j).
- Choose just one spell among the spells learned. Then, repeatedly use just the chosen spell to get from Town i to Town j.
At least how many spells does Snuke need to learn to achieve the objective above?
Constraints
- 2 \leq N \leq 500
- 0 \leq x_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq y_i \leq 10^9 (1 \leq i \leq N)
- (x_i, y_i) \neq (x_j, y_j) if i \neq j.
Input
Input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 \vdots x_N y_N
Output
Print the minimum number of spells Snuke needs to learn.
Sample Input 1
3 1 2 3 6 7 4
Sample Output 1
6
The figure below illustrates the positions of the towns (along with the coordinates of the four corners).
If Snuke learns the six spells below, he can get from Town i to Town j by using one of the spells once for every pair (i,j) (i \neq j), achieving his objective.
- (2, 4)
- (-2, -4)
- (4, -2)
- (-4, 2)
- (-6, -2)
- (6, 2)
Another option is to learn the six spells below. In this case, he can get from Town i to Town j by using one of the spells twice for every pair (i,j) (i \neq j), achieving his objective.
- (1, 2)
- (-1, -2)
- (2, -1)
- (-2, 1)
- (-3, -1)
- (3, 1)
There is no combination of spells that consists of less than six spells and achieve the objective, so we should print 6.
Sample Input 2
3 1 2 2 2 4 2
Sample Output 2
2
The optimal choice is to learn the two spells below:
- (1, 0)
- (-1, 0)
Sample Input 3
4 0 0 0 1000000000 1000000000 0 1000000000 1000000000
Sample Output 3
8
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
頂点に 1 から N の番号が、辺に 1 から M の番号がついた N 頂点 M 辺の重み付き単純連結無向グラフと正整数 K が与えられます。
辺 i\ (1\leq i\leq M) は頂点 u _ i と頂点 v _ i を結んでおり、重みは w _ i です。
このグラフの全域木 T に対して、T のコストを T に含まれる辺の重みの総和を K で割ったあまりで定めます。 このグラフの全域木のコストの最小値を求めてください。
制約
- 2\leq N\leq8
- N-1\leq M\leq\dfrac{N(N-1)}2
- 1\leq K\leq10^{15}
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M)
- 0\leq w _ i\lt K\ (1\leq i\leq M)
- 与えられるグラフは単純かつ連結
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K u _ 1 v _ 1 w _ 1 u _ 2 v _ 2 w _ 2 \vdots u _ M v _ M w _ M
出力
答えを出力せよ。
入力例 1
5 6 328 1 2 99 1 3 102 2 3 86 2 4 94 2 5 95 3 4 81
出力例 1
33
与えられるグラフは次のようになります。
辺 1,3,5,6 の 4 本を含む全域木のコストは (99+86+81+95)\bmod{328}=361\bmod{328}=33 となります。 このグラフの全域木のコストはすべて 33 以上であるため、33 を出力してください。
入力例 2
6 5 998244353 1 2 337361568 1 6 450343304 2 3 61477244 2 5 745383438 4 5 727360840
出力例 2
325437688
このグラフのただ一つの全域木のコスト 325437688 を出力してください。
入力例 3
8 28 936294041850197 1 2 473294720906780 1 3 743030800139244 1 4 709363019414774 1 5 383643612490312 1 6 557102781022861 1 7 623179288538138 1 8 739618599410809 2 3 857687812294404 2 4 893923168139714 2 5 581822471860662 2 6 740549363586558 2 7 307226438833222 2 8 447399029952998 3 4 636318083622768 3 5 44548707643622 3 6 307262781240755 3 7 12070267388230 3 8 700247263184082 4 5 560567890325333 4 6 704726113717147 4 7 588263818615687 4 8 549007536393172 5 6 779230871080408 5 7 825982583786498 5 8 713928998174272 6 7 751331074538826 6 8 449873635430228 7 8 11298381761479
出力例 3
11360716373
入力や答えが 32\operatorname{bit} 整数に収まらない場合があることに注意してください。
Score : 475 points
Problem Statement
You are given a weighted simple connected undirected graph with N vertices and M edges, where vertices are numbered 1 to N, and edges are numbered 1 to M. Additionally, a positive integer K is given.
Edge i\ (1\leq i\leq M) connects vertices u_i and v_i and has a weight of w_i.
For a spanning tree T of this graph, the cost of T is defined as the sum, modulo K, of the weights of the edges in T. Find the minimum cost of a spanning tree of this graph.
Constraints
- 2\leq N\leq8
- N-1\leq M\leq\dfrac{N(N-1)}2
- 1\leq K\leq10^{15}
- 1\leq u_i\lt v_i\leq N\ (1\leq i\leq M)
- 0\leq w_i\lt K\ (1\leq i\leq M)
- The given graph is simple and connected.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K u_1 v_1 w_1 u_2 v_2 w_2 \vdots u_M v_M w_M
Output
Print the answer.
Sample Input 1
5 6 328 1 2 99 1 3 102 2 3 86 2 4 94 2 5 95 3 4 81
Sample Output 1
33
The given graph is shown below:
The cost of the spanning tree containing edges 1,3,5,6 is (99+86+81+95)\bmod{328}=361\bmod{328}=33. The cost of every spanning tree of this graph is at least 33, so print 33.
Sample Input 2
6 5 998244353 1 2 337361568 1 6 450343304 2 3 61477244 2 5 745383438 4 5 727360840
Sample Output 2
325437688
Print the cost of the only spanning tree of this graph, which is 325437688.
Sample Input 3
8 28 936294041850197 1 2 473294720906780 1 3 743030800139244 1 4 709363019414774 1 5 383643612490312 1 6 557102781022861 1 7 623179288538138 1 8 739618599410809 2 3 857687812294404 2 4 893923168139714 2 5 581822471860662 2 6 740549363586558 2 7 307226438833222 2 8 447399029952998 3 4 636318083622768 3 5 44548707643622 3 6 307262781240755 3 7 12070267388230 3 8 700247263184082 4 5 560567890325333 4 6 704726113717147 4 7 588263818615687 4 8 549007536393172 5 6 779230871080408 5 7 825982583786498 5 8 713928998174272 6 7 751331074538826 6 8 449873635430228 7 8 11298381761479
Sample Output 3
11360716373
Note that the input and the answer may not fit into a 32\operatorname{bit} integer.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
高橋君は整数 x を持っています。はじめ、x = 0 です。
N 個の操作があります。i \, (1 \leq i \leq N) 個目の操作は整数 t_i, y_i を用いて以下のように表されます。
- t_i = 1 のとき、x を y_i で置き換える。
- t_i = 2 のとき、x を x + y_i で置き換える。
高橋君は 0 個以上 K 個以下の好きな個数の操作を無視することができます。残った操作を一度ずつ順序を変えずに行ったとき、最終的な x の値としてあり得る最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq N
- t_i \in \{1,2\} \, (1 \leq i \leq N)
- |y_i| \leq 10^9 \, (1 \leq i \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K t_1 y_1 \vdots t_N y_N
出力
答えを出力せよ。
入力例 1
5 1 2 4 2 -3 1 2 2 1 2 -3
出力例 1
3
5 個目の操作を無視すると、x は 0 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 と変化し、最終的な x の値は 3 となります。これが最大です。
入力例 2
1 0 2 -1000000000
出力例 2
-1000000000
入力例 3
10 3 2 3 2 -1 1 4 2 -1 2 5 2 -9 2 2 1 -6 2 5 2 -3
出力例 3
15
Score : 500 points
Problem Statement
Takahashi has an integer x. Initially, x = 0.
There are N operations. The i-th operation (1 \leq i \leq N) is represented by two integers t_i and y_i as follows:
- If t_i = 1, replace x with y_i.
- If t_i = 2, replace x with x + y_i.
Takahashi may skip any number between 0 and K (inclusive) of the operations. When he performs the remaining operations once each without changing the order, find the maximum possible final value of x.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq N
- t_i \in \{1,2\} \, (1 \leq i \leq N)
- |y_i| \leq 10^9 \, (1 \leq i \leq N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K t_1 y_1 \vdots t_N y_N
Output
Print the answer.
Sample Input 1
5 1 2 4 2 -3 1 2 2 1 2 -3
Sample Output 1
3
If he skips the 5-th operation, x changes as 0 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3, so x results in 3. This is the maximum.
Sample Input 2
1 0 2 -1000000000
Sample Output 2
-1000000000
Sample Input 3
10 3 2 3 2 -1 1 4 2 -1 2 5 2 -9 2 2 1 -6 2 5 2 -3
Sample Output 3
15