Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 桁の数字が表示される画面と、ボタンからなる機械があります。
画面に数字 k が表示されているとき、ボタンを 1 回押すと画面の数字が a_k に変わります。
0 が表示されている状態からボタンを 3 回押すと、画面には何が表示されますか?
制約
- 0\leq a_i \leq 9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
a_0 a_1 \dots a_9
出力
答えを出力せよ。
入力例 1
9 0 1 2 3 4 5 6 7 8
出力例 1
7
画面に表示される数字は、0 \rightarrow 9 \rightarrow 8 \rightarrow 7 と変化します。
入力例 2
4 8 8 8 0 8 8 8 8 8
出力例 2
4
画面に表示される数字は、0 \rightarrow 4 \rightarrow 0 \rightarrow 4 と変化します。
入力例 3
0 0 0 0 0 0 0 0 0 0
出力例 3
0
Score : 100 points
Problem Statement
There is a device with a screen that shows a single-digit number, and a button.
When the screen is showing a number k, pressing the button once changes the number on the screen to a_k.
The device currently shows 0. After pressing the button 3 times, what will be shown on the screen?
Constraints
- 0\leq a_i \leq 9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a_0 a_1 \dots a_9
Output
Print the answer.
Sample Input 1
9 0 1 2 3 4 5 6 7 8
Sample Output 1
7
The number on the screen transitions as 0 \rightarrow 9 \rightarrow 8 \rightarrow 7.
Sample Input 2
4 8 8 8 0 8 8 8 8 8
Sample Output 2
4
The number on the screen transitions as 0 \rightarrow 4 \rightarrow 0 \rightarrow 4.
Sample Input 3
0 0 0 0 0 0 0 0 0 0
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
チーム高橋とチーム青木が、チーム高橋を先攻として野球を行なっています。
現在、9 回表までが終了し、9 回裏が始まろうとしています。
試合において、チーム高橋は i 回表 (1\leq i\leq 9) に A_i 点を取り、チーム青木は j 回裏 (1\leq j\leq 8) に B_j 点を取りました。
ここで、9 回表の終了時点でチーム高橋の得点はチーム青木の得点以上です。
チーム青木は 9 回裏に最低何点取れば勝利することができるか求めてください。
ただし、9 回裏の終了時点で同点であった場合は引き分けとなり、すなわちチーム青木が勝利するためには 9 回裏の終了時点でチーム高橋より真に多くの点をとっている必要があるものとします。
なお、(ある時点における)チーム高橋の得点はそれまでの回の表に取った点数の合計であり、チーム青木の得点はそれまでの回の裏に取った点数の合計です。
制約
- 0\leq A_i, B_j\leq 99
- A_1 + A_2 + A_3 + A_4 + A_5 + A_6 + A_7 + A_8 + A_9 \geq B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7 + B_8
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3 A_4 A_5 A_6 A_7 A_8 A_9 B_1 B_2 B_3 B_4 B_5 B_6 B_7 B_8
出力
チーム青木が勝利するために 9 回裏に取る必要のある最小の得点を出力せよ。
入力例 1
0 1 0 1 2 2 0 0 1 1 1 0 0 0 0 1 0
出力例 1
5
9 回表の終了時点でチーム高橋の得点は 7 点、チーム青木の得点は 3 点となっています。
よって、チーム青木は9 回裏に 5 点取れば 7-8 となり、勝利することができます。
9 回裏に 4 点では、引き分けとなり勝利できないことに注意してください。
入力例 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
出力例 2
1
Score: 100 points
Problem Statement
Team Takahashi and Team Aoki are playing a baseball game, with Team Takahashi batting first.
Currently, the game has finished through the top of the ninth inning, and the bottom of the ninth is about to begin.
Team Takahashi scored A_i runs in the top of the i-th inning (1\leq i\leq 9), and Team Aoki scored B_j runs in the bottom of the j-th inning (1\leq j\leq 8).
At the end of the top of the ninth, Team Takahashi's score is not less than Team Aoki's score.
Determine the minimum number of runs Team Aoki needs to score in the bottom of the ninth to win the game.
Here, if the game is tied at the end of the bottom of the ninth, it results in a draw. Therefore, for Team Aoki to win, they must score strictly more runs than Team Takahashi by the end of the bottom of the ninth.
Team Takahashi's score at any point is the total runs scored in the tops of the innings up to that point, and Team Aoki's score is the total runs scored in the bottoms of the innings.
Constraints
- 0\leq A_i, B_j\leq 99
- A_1 + A_2 + A_3 + A_4 + A_5 + A_6 + A_7 + A_8 + A_9 \geq B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7 + B_8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3 A_4 A_5 A_6 A_7 A_8 A_9 B_1 B_2 B_3 B_4 B_5 B_6 B_7 B_8
Output
Print the minimum number of runs Team Aoki needs to score in the bottom of the ninth inning to win.
Sample Input 1
0 1 0 1 2 2 0 0 1 1 1 0 0 0 0 1 0
Sample Output 1
5
At the end of the top of the ninth inning, Team Takahashi has scored seven runs, and Team Aoki has scored three runs.
Therefore, if Team Aoki scores five runs in the bottom of the ninth, the scores will be 7-8, allowing them to win.
Note that scoring four runs would result in a draw and not a victory.
Sample Input 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 2
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は英小文字からなる文字列 S をキーボードで入力しようとしました。
高橋君は画面を見ずにキーボードだけを見てタイピングをしていました。
誤って別の英小文字を入力してしまったときにはその直後にバックスペースキーを押しましたが、バックスペースキーが壊れていたため誤って入力された文字は消去されず、実際に入力された文字列は文字列 T となりました。
また、英小文字以外のキーを誤って押してしまうことはありませんでした。
T のうち高橋君が誤って入力した文字でないものを正しく入力された文字であると定めます。
正しく入力された文字が T の何文字目であるか答えてください。
制約
- S, T は長さ 1 以上 2 \times 10^5 以下の英小文字からなる文字列
- T は問題文中の手続きにより得られる文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S の長さを |S| として、正しく入力された文字が A_1, A_2, \ldots, A_{|S|} 文字目であるとき A_1, A_2, \ldots, A_{|S|} の値をこの順に空白区切りで出力せよ。
ただし、出力は昇順になるようにせよ。すなわち、各 1 \leq i \leq |S| - 1 に対して A_i < A_{i + 1} を満たすようにせよ。
入力例 1
abc axbxyc
出力例 1
1 3 6
高橋君のタイピングの一連の流れは以下のようになります。
aを入力する。bを入力しようとするが、誤ってxを入力してしまう。- バックスペースキーを押すが、文字の削除は行われない。
bを入力する。cを入力しようとするが、誤ってxを入力してしまう。- バックスペースキーを押すが、文字の削除は行われない。
cを入力しようとするが、誤ってyを入力してしまう。- バックスペースキーを押すが、文字の削除は行われない。
cを入力する。
正しく入力された文字は 1, 3, 6 文字目です。
入力例 2
aaaa bbbbaaaa
出力例 2
5 6 7 8
入力例 3
atcoder atcoder
出力例 3
1 2 3 4 5 6 7
高橋君が誤った文字を入力することはありませんでした。
Score: 200 points
Problem Statement
Takahashi tried to type a string S consisting of lowercase English letters using a keyboard.
He was typing while looking only at the keyboard, not the screen.
Whenever he mistakenly typed a different lowercase English letter, he immediately pressed the backspace key. However, the backspace key was broken, so the mistakenly typed letter was not deleted, and the actual string typed was T.
He did not mistakenly press any keys other than those for lowercase English letters.
The characters in T that were not mistakenly typed are called correctly typed characters.
Determine the positions in T of the correctly typed characters.
Constraints
- S and T are strings of lowercase English letters with lengths between 1 and 2 \times 10^5, inclusive.
- T is a string obtained by the procedure described in the problem statement.
Input
The input is given from Standard Input in the following format:
S T
Output
Let |S| be the length of S. If the correctly typed characters are the A_1-th, A_2-th, \ldots, A_{|S|}-th characters of T, print the values of A_1, A_2, \ldots, A_{|S|} in this order, separated by spaces.
Ensure that the output is in ascending order. That is, A_i < A_{i + 1} should hold for each 1 \leq i \leq |S| - 1.
Sample Input 1
abc axbxyc
Sample Output 1
1 3 6
The sequence of Takahashi's typing is as follows:
- Type
a. - Try to type
bbut mistakenly typex. - Press the backspace key, but the character is not deleted.
- Type
b. - Try to type
cbut mistakenly typex. - Press the backspace key, but the character is not deleted.
- Try to type
cbut mistakenly typey. - Press the backspace key, but the character is not deleted.
- Type
c.
The correctly typed characters are the first, third, and sixth characters.
Sample Input 2
aaaa bbbbaaaa
Sample Output 2
5 6 7 8
Sample Input 3
atcoder atcoder
Sample Output 3
1 2 3 4 5 6 7
Takahashi did not mistakenly type any characters.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 A,B が K 進法表記で与えられます。
A \times B を 10 進法表記で出力してください。
注記
K 進法表記については、Wikipedia「位取り記数法」 を参照してください。
制約
- 2 \leq K \leq 10
- 1 \leq A,B \leq 10^5
- A,B は K 進法表記で与えられる
入力
入力は以下の形式で標準入力から与えられる。
K A B
出力
答えを出力せよ。
入力例 1
2 1011 10100
出力例 1
220
2 進法表記の 1011 を 、10 進法表記すると 11 です。
2 進法表記の 10100 を、 10 進法表記すると 20 です。
11 \times 20 = 220 なので 220 を出力します。
入力例 2
7 123 456
出力例 2
15642
7 進法表記の 123 を 、10 進法表記すると 66 です。
7 進法表記の 456 を、 10 進法表記すると 237 です。
66 \times 237 = 15642 なので 15642 を出力します。
Score : 200 points
Problem Statement
You are given integers A and B, in base K.
Print A \times B in decimal.
Notes
For base-K representation, see Wikipedia's article on Positional notation.
Constraints
- 2 \leq K \leq 10
- 1 \leq A,B \leq 10^5
- A and B are in base-K representation.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the answer.
Sample Input 1
2 1011 10100
Sample Output 1
220
1011 in base 2 corresponds to 11 in base 10.
10100 in base 2 corresponds to 20 in base 10.
We have 11 \times 20 = 220, so print 220.
Sample Input 2
7 123 456
Sample Output 2
15642
123 in base 7 corresponds to 66 in base 10.
456 in base 7 corresponds to 237 in base 10.
We have 66 \times 237 = 15642, so print 15642.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
頂点 1, 頂点 2,\ldots, 頂点 N の N 個の頂点からなる単純無向グラフ G,H が与えられます。 G には M _ G 本の辺があり、i 本目 (1\leq i\leq M _ G) の辺は頂点 u _ i と頂点 v _ i を結んでいます。 H には M _ H 本の辺があり、i 本目 (1\leq i\leq M _ H) の辺は頂点 a _ i と頂点 b _ i を結んでいます。
あなたは、グラフ H に対して次の操作を 0 回以上の好きな回数繰り返すことができます。
- 1\leq i\lt j\leq N を満たす整数の組 (i,j) をひとつ選ぶ。A _ {i,j} 円を支払って、頂点 i と頂点 j を結ぶ辺がなければ追加し、あれば取り除く。
G と H を同型にするために少なくとも何円支払う必要があるか求めてください。
単純無向グラフとは?
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
グラフの同型とは?
N 頂点のグラフ G と H が同型であるとは、ある (1,2,\ldots,N) の並べ替え (P _ 1,P _ 2,\ldots,P _ N) が存在して、どの 1\leq i\lt j\leq N に対しても
- G に頂点 i, 頂点 j を結ぶ辺が存在するとき、かつそのときに限り H に頂点 P _ i, 頂点 P _ j を結ぶ辺が存在する
制約
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
出力
答えを出力せよ。
入力例 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
出力例 1
9
与えられたグラフはそれぞれ以下のようになります。

たとえば、H に対して次のような 4 つの操作を順に行うことで、9 円を支払ってG と H を同型にすることができます。
- (i,j)=(1,3) として操作を行う。H には頂点 1 と頂点 3 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(2,5) として操作を行う。H には頂点 2 と頂点 5 を結ぶ辺はないので、2 円を支払ってこれを追加する。
- (i,j)=(1,5) として操作を行う。H には頂点 1 と頂点 5 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(3,5) として操作を行う。H には頂点 3 と頂点 5 を結ぶ辺はないので、5 円を支払ってこれを追加する。
操作の結果、H は以下のようになります。

支払う金額を 8 円以下にして G と H を同型にすることはできないため、9 を出力してください。
入力例 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
出力例 2
3
たとえば、(i,j)=(2,3),(2,4),(3,4) とした 3 回の操作を行うことで G と H を同型にすることができます。
入力例 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
出力例 3
5
たとえば、(i,j)=(4,5) とした 1 回の操作を行うことで G と H を同型にすることができます。
入力例 4
2 0 0 371
出力例 4
0
G や H には辺が含まれていないこともあります。 また、一度も操作をする必要がないこともあります。
入力例 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
出力例 5
21214
Score : 300 points
Problem Statement
You are given simple undirected graphs G and H, each with N vertices: vertices 1, 2, \ldots, N. Graph G has M_G edges, and its i-th edge (1\leq i\leq M_G) connects vertices u_i and v_i. Graph H has M_H edges, and its i-th edge (1\leq i\leq M_H) connects vertices a_i and b_i.
You can perform the following operation on graph H any number of times, possibly zero.
- Choose a pair of integers (i,j) satisfying 1\leq i<j\leq N. Pay A_{i,j} yen, and if there is no edge between vertices i and j in H, add one; if there is, remove it.
Find the minimum total cost required to make G and H isomorphic.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges, where edges have no direction.
What does it mean for graphs to be isomorphic?
Two graphs G and H with N vertices are isomorphic if and only if there exists a permutation (P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) such that for all 1\leq i\lt j\leq N:
- an edge exists between vertices i and j in G if and only if an edge exists between vertices P_i and P_j in H.
Constraints
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
Output
Print the answer.
Sample Input 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
Sample Output 1
9
The given graphs are as follows:

For example, you can perform the following four operations on H to make it isomorphic to G at a cost of 9 yen.
- Choose (i,j)=(1,3). There is an edge between vertices 1 and 3 in H, so pay 1 yen to remove it.
- Choose (i,j)=(2,5). There is no edge between vertices 2 and 5 in H, so pay 2 yen to add it.
- Choose (i,j)=(1,5). There is an edge between vertices 1 and 5 in H, so pay 1 yen to remove it.
- Choose (i,j)=(3,5). There is no edge between vertices 3 and 5 in H, so pay 5 yen to add it.
After these operations, H becomes:

You cannot make G and H isomorphic at a cost less than 9 yen, so print 9.
Sample Input 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
Sample Output 2
3
For example, performing the operations (i,j)=(2,3),(2,4),(3,4) on H will make it isomorphic to G.
Sample Input 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
Sample Output 3
5
For example, performing the operation (i,j)=(4,5) once will make G and H isomorphic.
Sample Input 4
2 0 0 371
Sample Output 4
0
Note that G and H may have no edges.
Also, it is possible that no operations are needed.
Sample Input 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
Sample Output 5
21214
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 王国には 1 から N まで番号がつけられた N 個の城壁があります。また、 M 個の砲台があります。
砲台 i は L_i 以上 R_i 以下の番号の城壁を守っています。
ある砲台を破壊すると、その砲台が守っていた城壁はその砲台により守られなくなります。
どの砲台にも守られていない城壁が存在する状態にするためには、最小で何個の砲台を破壊する必要がありますか?
制約
- 1 \leq N \leq 10^6
- 1 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M L_1 R_1 L_2 R_2 \vdots L_M R_M
出力
砲台に守られていない城壁が存在する状態にするために破壊する必要がある砲台の個数の最小値を出力せよ。
入力例 1
10 4 1 6 4 5 5 10 7 10
出力例 1
1
砲台 1 を破壊するとどの砲台も城壁 3 を守っていない状態になります。 また、砲台を 1 個も破壊しなければ全ての城壁がどれかの砲台に守られている状態になります。 そのため、1 を出力します。
入力例 2
5 2 1 2 3 4
出力例 2
0
どの砲台も城壁 5 を守っていないため、砲台を 1 個も破壊しないでも砲台に守られていない城壁が存在する状態になります。そのため、0 を出力します。
入力例 3
5 10 2 5 1 5 1 2 2 4 2 2 5 5 2 4 1 2 2 2 2 3
出力例 3
3
Score : 300 points
Problem Statement
In the AtCoder Kingdom, there are N castle walls numbered from 1 through N. There are also M turrets.
Turret i guards castle walls numbered from L_i through R_i.
When a turret is destroyed, the castle walls that were guarded by that turret are no longer guarded by that turret.
What is the minimum number of turrets that need to be destroyed so that at least one castle wall is not guarded by any turret?
Constraints
- 1 \leq N \leq 10^6
- 1 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M L_1 R_1 L_2 R_2 \vdots L_M R_M
Output
Output the minimum number of turrets that need to be destroyed so that at least one castle wall is not guarded by any turret.
Sample Input 1
10 4 1 6 4 5 5 10 7 10
Sample Output 1
1
If turret 1 is destroyed, no turret guards castle wall 3. Also, if no turrets are destroyed, all castle walls are guarded by some turret. Therefore, output 1.
Sample Input 2
5 2 1 2 3 4
Sample Output 2
0
Since no turret guards castle wall 5, there already exists a castle wall not guarded by any turret without destroying any turrets. Therefore, output 0.
Sample Input 3
5 10 2 5 1 5 1 2 2 4 2 2 5 5 2 4 1 2 2 2 2 3
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君が主催するコンテストに、1 から N までの番号が付けられた N 人の選手が参加しています。 このコンテストは各選手がその得点を競うものであり、現在の得点はどの選手も 0 点です。
未来予知の能力を持つ高橋君は、今から選手たちの得点がどのように変動するかを知っています。 具体的には、i=1,2,\dots,T について、今から i 秒後に選手 A_i の得点が B_i 点増加します。 逆に、それ以外に得点の変動はありません。
得点の多様性を好む高橋君は、各時点における選手たちの得点に何種類の値が現れるかを知りたがっています。 i=1,2,\dots,T それぞれについて、今から i+0.5 秒後の選手たちの得点には何種類の値が現れるか求めてください。
例えば、ある時点における選手たちの得点がそれぞれ 10,20,30,20 点であった場合、この時点での選手たちの得点には 3 種類の値が現れています。
制約
- 1\leq N, T\leq 2\times 10^5
- 1\leq A_i \leq N
- 1\leq B_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T A_1 B_1 A_2 B_2 \vdots A_T B_T
出力
T 行出力せよ。 i\ (1\leq i \leq T) 行目には、今から i+0.5 秒後の選手たちの得点には何種類の値が現れるかを整数として出力せよ。
入力例 1
3 4 1 10 3 20 2 10 2 10
出力例 1
2 3 2 2
選手 1,2,3 の得点をこの順に並べた数列を S とします。 現在、S=\lbrace 0,0,0\rbrace です。
- 1 秒後に選手 1 の得点が 10 点増加し、S=\lbrace 10,0,0\rbrace になります。よって、1.5 秒後の選手たちの得点には 2 種類の値が現れます。
- 2 秒後に選手 3 の得点が 20 点増加し、S=\lbrace 10,0,20\rbrace になります。よって、2.5 秒後の選手たちの得点には 3 種類の値が現れます。
- 3 秒後に選手 2 の得点が 10 点増加し、S=\lbrace 10,10,20\rbrace になります。よって、3.5 秒後の選手たちの得点には 2 種類の値が現れます。
- 4 秒後に選手 2 の得点が 10 点増加し、S=\lbrace 10,20,20\rbrace になります。よって、4.5 秒後の選手たちの得点には 2 種類の値が現れます。
入力例 2
1 3 1 3 1 4 1 3
出力例 2
1 1 1
入力例 3
10 10 7 2620 9 2620 8 3375 1 3375 6 1395 5 1395 6 2923 10 3375 9 5929 5 1225
出力例 3
2 2 3 3 4 4 5 5 6 5
Score: 400 points
Problem Statement
Takahashi is hosting a contest with N players numbered 1 to N. The players will compete for points. Currently, all players have zero points.
Takahashi's foreseeing ability lets him know how the players' scores will change. Specifically, for i=1,2,\dots,T, the score of player A_i will increase by B_i points at i seconds from now. There will be no other change in the scores.
Takahashi, who prefers diversity in scores, wants to know how many different score values will appear among the players' scores at each moment. For each i=1,2,\dots,T, find the number of different score values among the players' scores at i+0.5 seconds from now.
For example, if the players have 10, 20, 30, and 20 points at some moment, there are three different score values among the players' scores at that moment.
Constraints
- 1\leq N, T\leq 2\times 10^5
- 1\leq A_i \leq N
- 1\leq B_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T A_1 B_1 A_2 B_2 \vdots A_T B_T
Output
Print T lines. The i-th line (1\leq i \leq T) should contain an integer representing the number of different score values among the players' scores at i+0.5 seconds from now.
Sample Input 1
3 4 1 10 3 20 2 10 2 10
Sample Output 1
2 3 2 2
Let S be the sequence of scores of players 1, 2, 3 in this order. Currently, S=\lbrace 0,0,0\rbrace.
- After one second, the score of player 1 increases by 10 points, making S=\lbrace 10,0,0\rbrace. Thus, there are two different score values among the players' scores at 1.5 seconds from now.
- After two seconds, the score of player 3 increases by 20 points, making S=\lbrace 10,0,20\rbrace. Thus, there are three different score values among the players' scores at 2.5 seconds from now.
- After three seconds, the score of player 2 increases by 10 points, making S=\lbrace 10,10,20\rbrace. Therefore, there are two different score values among the players' scores at 3.5 seconds from now.
- After four seconds, the score of player 2 increases by 10 points, making S=\lbrace 10,20,20\rbrace. Therefore, there are two different score values among the players' scores at 4.5 seconds from now.
Sample Input 2
1 3 1 3 1 4 1 3
Sample Output 2
1 1 1
Sample Input 3
10 10 7 2620 9 2620 8 3375 1 3375 6 1395 5 1395 6 2923 10 3375 9 5929 5 1225
Sample Output 3
2 2 3 3 4 4 5 5 6 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
以下の条件をすべて満たす長さ X_1+X_2+X_3 の数列 A = (a_1, \cdots, a_{X_1 + X_2 + X_3}) としてあり得るものの個数を 998244353 で割ったあまりを求めてください。
- A は 1 を X_1 個、2 を X_2 個、3 を X_3 個含む。
- 隣接する要素の差の絶対値は 1 以下である。つまり、1 \leq i \leq X_1+X_2+X_3-1 を満たす任意の整数 i について、|a_{i+1} - a_i| \leq 1 が成り立つ。
制約
- 1 \leq X_1, X_2, X_3 \leq 10^6
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X_1 X_2 X_3
出力
答えを出力せよ。
入力例 1
2 2 1
出力例 1
9
条件を満たす数列は以下の 9 通りです。
- (1, 1, 2, 2, 3)
- (1, 1, 2, 3, 2)
- (1, 2, 1, 2, 3)
- (1, 2, 3, 2, 1)
- (2, 1, 1, 2, 3)
- (2, 3, 2, 1, 1)
- (3, 2, 1, 1, 2)
- (3, 2, 1, 2, 1)
- (3, 2, 2, 1, 1)
入力例 2
5 3 4
出力例 2
204
入力例 3
998244 998353 998107
出力例 3
701926019
Score : 450 points
Problem Statement
Find the number, modulo 998244353, of sequences A = (a_1, \cdots, a_{X_1 + X_2 + X_3}) of length X_1+X_2+X_3 that satisfy all of the following conditions.
- A contains exactly X_1 copies of 1, exactly X_2 copies of 2, and exactly X_3 copies of 3.
- The absolute difference between adjacent elements is at most 1. That is, for every integer i satisfying 1 \leq i \leq X_1+X_2+X_3-1, we have |a_{i+1} - a_i| \leq 1.
Constraints
- 1 \leq X_1, X_2, X_3 \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X_1 X_2 X_3
Output
Output the answer.
Sample Input 1
2 2 1
Sample Output 1
9
The sequences satisfying the conditions are the following nine:
- (1, 1, 2, 2, 3)
- (1, 1, 2, 3, 2)
- (1, 2, 1, 2, 3)
- (1, 2, 3, 2, 1)
- (2, 1, 1, 2, 3)
- (2, 3, 2, 1, 1)
- (3, 2, 1, 1, 2)
- (3, 2, 1, 2, 1)
- (3, 2, 2, 1, 1)
Sample Input 2
5 3 4
Sample Output 2
204
Sample Input 3
998244 998353 998107
Sample Output 3
701926019
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
xy 平面上にある AtCoder 王国の道路は、全ての整数 n に対する直線 x=n および直線 y=n からなります。 そのうち、全ての整数 n に対する直線 x=Bn および直線 y=Bn は大通りです。
高橋君は (x,y) にいるときに、(x,y-1),(x,y+1),(x+1,y),(x-1,y) のいずれかに移動することができます。 また、1 回の移動につき、大通りに沿って移動する場合は 1 秒、それ以外の場合は K 秒かかります。
(S_x,S_y) にいる高橋君が (G_x,G_y) に移動するのに最短で何秒かかるかを求めてください。
この問題は T ケース与えられます。
制約
- 1 \le T \le 2 \times 10^5
- 1 \le B,K \le 10^9
- 0 \le S_x,S_y,G_x,G_y \le 10^9
- 入力はすべて整数。
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{testcase}_1
\mathrm{testcase}_2
\vdots
\mathrm{testcase}_T
それぞれのテストケースは以下の形式で与えられる。
B K S_x S_y G_x G_y
出力
T 行出力せよ。i 行目には i 個目のテストケースの解を出力せよ。
入力例 1
4 3 4 2 2 4 4 5 6 2 3 2 3 1 1000000000 0 0 1000000000 1000000000 1000000000 1000000000 500000000 500000000 1000000000 1000000000
出力例 1
10 0 2000000000 500000000500000000
1 個目のテストケースについて、(2,2) から (2,3) に 4 秒かけて移動し、(2,3) から (4,3) に 2 秒かけて移動し、(4,3) から (4,4) に 4 秒かけて移動することで 10 秒で (2,2) から (4,4) に移動することができます。10 秒より早く移動することはできないため、解は 10 です。
2 個目のテストケースについて、初めから (G_x,G_y) にいるため解は 0 です。
入力例 2
10 928184439 674654465 203937094 186855052 851783856 805293696 55480262 448852233 823161539 786348805 550018803 322680316 891870741 235679524 32164572 497841190 620600021 96487871 321502816 428964257 499656016 521484999 717623189 824784374 144040837 680268887 76238777 371138006 350230937 78690135 768922620 799628518 403830696 60449731 218880692 88319939 482031503 121412614 472330444 284479575 949635609 427232765 389524418 132987043 656496997 678732442 23028233 488463974 857778764 629964237 714551548 739330018 579247790 874251485 461612428 535402609 555160129 833592114 44418273 287363785
出力例 2
177606591118701316 6205925075792263 30320747646118343 84136273267803188 83764071874751489 118960470930399064 2929499649126153 16403238161749820 84995699148879437 71771264361119335
Score : 500 points
Problem Statement
The roads in the Kingdom of AtCoder, which lies on the xy-plane, are the lines x=n and y=n for all integers n. Among them, the lines x=Bn and y=Bn for all integers n are main roads.
When Takahashi is at (x,y), he can move to (x,y-1), (x,y+1), (x+1,y), or (x-1,y). Each move takes 1 second along a main road and K seconds otherwise.
Find the minimum number of seconds Takahashi needs to get from (S_x, S_y) to (G_x, G_y).
You will have T test cases to solve.
Constraints
- 1 \le T \le 2 \times 10^5
- 1 \le B,K \le 10^9
- 0 \le S_x,S_y,G_x,G_y \le 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
\mathrm{testcase}_1
\mathrm{testcase}_2
\vdots
\mathrm{testcase}_T
Each test case is in the following format:
B K S_x S_y G_x G_y
Output
Print T lines. The i-th line should contain the answer to the i-th test case.
Sample Input 1
4 3 4 2 2 4 4 5 6 2 3 2 3 1 1000000000 0 0 1000000000 1000000000 1000000000 1000000000 500000000 500000000 1000000000 1000000000
Sample Output 1
10 0 2000000000 500000000500000000
For the 1-st test case, he can go from (2,2) to (2,3) in 4 seconds, from (2,3) to (4,3) in 2 seconds, and from (4,3) to (4,4) in 4 seconds to get from (2,2) to (4,4) in 10 seconds. It is impossible to get there in less than 10 seconds, so the answer is 10.
For the 2-nd test case, he is already at (G_x, G_y) in the beginning, so the answer is 0.
Sample Input 2
10 928184439 674654465 203937094 186855052 851783856 805293696 55480262 448852233 823161539 786348805 550018803 322680316 891870741 235679524 32164572 497841190 620600021 96487871 321502816 428964257 499656016 521484999 717623189 824784374 144040837 680268887 76238777 371138006 350230937 78690135 768922620 799628518 403830696 60449731 218880692 88319939 482031503 121412614 472330444 284479575 949635609 427232765 389524418 132987043 656496997 678732442 23028233 488463974 857778764 629964237 714551548 739330018 579247790 874251485 461612428 535402609 555160129 833592114 44418273 287363785
Sample Output 2
177606591118701316 6205925075792263 30320747646118343 84136273267803188 83764071874751489 118960470930399064 2929499649126153 16403238161749820 84995699148879437 71771264361119335