実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君と青木君はジョギングをすることにしました。
高橋君は「A 秒間秒速 B メートルで歩き、C 秒間休む」ことを繰り返します。
青木君は「D 秒間秒速 E メートルで歩き、F 秒間休む」ことを繰り返します。
二人が同時にジョギングを始めてから X 秒後、高橋君と青木君のうちどちらが長い距離を進んでいますか?
制約
- 1 \leq A, B, C, D, E, F, X \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E F X
出力
二人が同時にジョギングを始めてから X 秒後時点で、高橋君の方が青木君よりも長い距離を進んでいるならば Takahashi、青木君の方が高橋君よりも長い距離を進んでいるならば Aoki、二人が同じ距離を進んでいるならば Draw と出力せよ。
入力例 1
4 3 3 6 2 5 10
出力例 1
Takahashi
二人はジョギングを始めてから 10 秒間の間、以下のように行動します。
- 高橋君は 4 秒間歩き、3 秒間休んだ後、再び 3 秒間歩く。合計 (4 + 3) \times 3 = 21 メートル歩く。
- 青木君は 6 秒間歩き、4 秒間休む。合計 6 \times 2 = 12 メートル歩く。
高橋君の方が長い距離を進んでいるので、Takahashi と出力します。
入力例 2
3 1 4 1 5 9 2
出力例 2
Aoki
入力例 3
1 1 1 1 1 1 1
出力例 3
Draw
Score : 100 points
Problem Statement
Takahashi and Aoki decided to jog.
Takahashi repeats the following: "walk at B meters a second for A seconds and take a rest for C seconds."
Aoki repeats the following: "walk at E meters a second for D seconds and take a rest for F seconds."
When X seconds have passed since they simultaneously started to jog, which of Takahashi and Aoki goes ahead?
Constraints
- 1 \leq A, B, C, D, E, F, X \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E F X
Output
When X seconds have passed since they simultaneously started to jog, if Takahashi goes ahead of Aoki, print Takahashi; if Aoki goes ahead of Takahashi, print Aoki; if they have advanced the same distance, print Draw.
Sample Input 1
4 3 3 6 2 5 10
Sample Output 1
Takahashi
During the first 10 seconds after they started to jog, they move as follows.
- Takahashi walks for 4 seconds, takes a rest for 3 seconds, and walks again for 3 seconds. As a result, he advances a total of (4 + 3) \times 3 = 21 meters.
- Aoki walks for 6 seconds and takes a rest for 4 seconds. As a result, he advances a total of 6 \times 2 = 12 meters.
Since Takahashi goes ahead, Takahashi should be printed.
Sample Input 2
3 1 4 1 5 9 2
Sample Output 2
Aoki
Sample Input 3
1 1 1 1 1 1 1
Sample Output 3
Draw
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
サンタさんに手紙を出したい高橋くんは、 X 円切手が 1 枚だけ貼られた封筒を用意しました。
サンタさんに手紙を届けるためには、貼られている切手の総額が Y 円以上である必要があります。
高橋くんは、この封筒に 10 円切手を何枚か貼り足すことで、貼られている切手の総額を Y 円以上にしたいです。
高橋くんはこの封筒に、最小で何枚の 10 円切手を貼り足す必要がありますか?
制約
- X,Y は整数
- 1 \le X,Y \le 1000
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
答えを整数として出力せよ。
入力例 1
80 94
出力例 1
2
- 80 円切手に 0 枚の 10 円切手を貼り足せば総額が 80 円となり、これは手紙を届けるのに必要な 94 円未満です。
- 80 円切手に 1 枚の 10 円切手を貼り足せば総額が 90 円となり、これは手紙を届けるのに必要な 94 円未満です。
- 80 円切手に 2 枚の 10 円切手を貼り足せば総額が 100 円となり、これは手紙を届けるのに必要な 94 円以上です。
入力例 2
1000 63
出力例 2
0
もともと貼られている切手だけで金額が十分である可能性もあります。
入力例 3
270 750
出力例 3
48
Score : 100 points
Problem Statement
Takahashi wants to send a letter to Santa Claus. He has an envelope with an X-yen (Japanese currency) stamp stuck on it.
To be delivered to Santa Claus, the envelope must have stamps in a total value of at least Y yen.
Takahashi will put some more 10-yen stamps so that the envelope will have stamps worth at least Y yen in total.
At least how many more 10-yen stamps does Takahashi need to put on the envelope?
Constraints
- X and Y are integers.
- 1 \le X,Y \le 1000
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the answer as an integer.
Sample Input 1
80 94
Sample Output 1
2
- After adding zero 10-yen stamps to the 80-yen stamp, the total is 80 yen, which is less than the required amount of 94 yen.
- After adding one 10-yen stamp to the 80-yen stamp, the total is 90 yen, which is less than the required amount of 94 yen.
- After adding two 10-yen stamps to the 80-yen stamp, the total is 100 yen, which is not less than the required amount of 94 yen.
Sample Input 2
1000 63
Sample Output 2
0
The envelope may already have a stamp with enough value.
Sample Input 3
270 750
Sample Output 3
48
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
直線上に 7 個の点 A, B, C, D, E, F, G がこの順に並んでいます。(下の図も参考にしてください)
隣り合う点の距離は次の通りです。
- 点 A と点 B の距離は 3
- 点 B と点 C の距離は 1
- 点 C と点 D の距離は 4
- 点 D と点 E の距離は 1
- 点 E と点 F の距離は 5
- 点 F と点 G の距離は 9

2 つの英大文字 p, q が与えられます。p, q は A,B,C,D,E,F,G のいずれかで、 p \neq q が成り立ちます。
点 p と点 q の間の距離を答えてください。
制約
- p, q は
A,B,C,D,E,F,Gのいずれか - p \neq q
入力
入力は以下の形式で標準入力から与えられる。
p q
出力
点 p と点 q の間の距離を出力せよ。
入力例 1
A C
出力例 1
4
点 A と点 C の距離は 3 + 1 = 4 です。
入力例 2
G B
出力例 2
20
点 G と点 B の距離は 9 + 5 + 1 + 4 + 1 = 20 です。
入力例 3
C F
出力例 3
10
Score : 200 points
Problem Statement
There are 7 points A, B, C, D, E, F, and G on a straight line, in this order. (See also the figure below.)
The distances between adjacent points are as follows.
- Between A and B: 3
- Between B and C: 1
- Between C and D: 4
- Between D and E: 1
- Between E and F: 5
- Between F and G: 9

You are given two uppercase English letters p and q. Each of p and q is A, B, C, D, E, F, or G, and it holds that p \neq q.
Find the distance between the points p and q.
Constraints
- Each of p and q is
A,B,C,D,E,F, orG. - p \neq q
Input
The input is given from Standard Input in the following format:
p q
Output
Print the distance between the points p and q.
Sample Input 1
A C
Sample Output 1
4
The distance between the points A and C is 3 + 1 = 4.
Sample Input 2
G B
Sample Output 2
20
The distance between the points G and B is 9 + 5 + 1 + 4 + 1 = 20.
Sample Input 3
C F
Sample Output 3
10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数からなる長さ N の数列 A=(A_1,\ldots,A_N) があります。どの隣接する 2 項の値も相異なります。
この数列に対し、次の操作によりいくつか数を挿入します。
- 数列 A のどの隣接する 2 項の差の絶対値も 1 であるとき、操作を終了する。
- 数列 A の先頭から見て、隣接する 2 項の差の絶対値が 1 でない最初の箇所を A_i,A_{i+1} とする。
- A_i < A_{i+1} ならば、A_i と A_{i+1} の間に、A_i+1,A_i+2,\ldots,A_{i+1}-1 を挿入する。
- A_i > A_{i+1} ならば、A_i と A_{i+1} の間に、A_i-1,A_i-2,\ldots,A_{i+1}+1 を挿入する。
- 手順 1 に戻る。
操作が終了したときの数列を出力してください。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
操作が終了したときの数列の各要素を空白区切りで出力せよ。
入力例 1
4 2 5 1 2
出力例 1
2 3 4 5 4 3 2 1 2
最初、数列は (2,5,1,2) です。操作は以下のように行われます。
- 1 項目の 2 と 2 項目の 5 の間に 3,4 を挿入する。数列は (2,3,4,5,1,2) となる。
- 4 項目の 5 と 5 項目の 1 の間に 4,3,2 を挿入する。数列は (2,3,4,5,4,3,2,1,2) となる。
入力例 2
6 3 4 5 6 5 4
出力例 2
3 4 5 6 5 4
一度も挿入が行われないこともあります。
Score : 200 points
Problem Statement
We have a sequence of length N consisting of positive integers: A=(A_1,\ldots,A_N). Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in A has an absolute difference of 1, terminate the procedure.
- Let A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of A whose absolute difference is not 1.
- If A_i < A_{i+1}, insert A_i+1,A_i+2,\ldots,A_{i+1}-1 between A_i and A_{i+1}.
- If A_i > A_{i+1}, insert A_i-1,A_i-2,\ldots,A_{i+1}+1 between A_i and A_{i+1}.
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the terms in the sequence when the procedure ends, separated by spaces.
Sample Input 1
4 2 5 1 2
Sample Output 1
2 3 4 5 4 3 2 1 2
The initial sequence is (2,5,1,2). The procedure goes as follows.
- Insert 3,4 between the first term 2 and the second term 5, making the sequence (2,3,4,5,1,2).
- Insert 4,3,2 between the fourth term 5 and the fifth term 1, making the sequence (2,3,4,5,4,3,2,1,2).
Sample Input 2
6 3 4 5 6 5 4
Sample Output 2
3 4 5 6 5 4
No insertions may be performed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
H 行 W 列の格子状に HW 枚のカードが並べられています。
i=1,\ldots,N について、上から A_i 行目、左から B_i 列目にあるカードには数 i が書かれており、それ以外の HW-N 枚のカードには何も書かれていません。
これらのカードに対し、以下の 2 種類の操作を可能な限り繰り返します。
- 数の書かれたカードを含まない行が存在するとき、その行のカードを全て取り除き、残りのカードを上へ詰める
- 数の書かれたカードを含まない列が存在するとき、その列のカードを全て取り除き、残りのカードを左へ詰める
操作が終了したとき、数が書かれたカードがそれぞれどこにあるか求めてください。なお、答えは操作の仕方に依らず一意に定まることが証明されます。
制約
- 1 \leq H,W \leq 10^9
- 1 \leq N \leq \min(10^5,HW)
- 1 \leq A_i \leq H
- 1 \leq B_i \leq W
- (A_i,B_i) は相異なる
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
H W N A_1 B_1 \vdots A_N B_N
出力
N 行出力せよ。
操作終了後に数 i が書かれたカードが上から C_i 行目、左から D_i 列目に存在するとき、i 行目には C_i,D_i をこの順に空白区切りで出力せよ。
入力例 1
4 5 2 3 2 2 5
出力例 1
2 1 1 2
何も書かれていないカードを * で表すことにします。最初、カードの配置は以下の通りです。
***** ****2 *1*** *****
操作終了後、カードの配置は以下の通りになります。
*2 1*
1 が書かれたカードは上から 2 行目、左から 1 列目にあり、2 が書かれたカードは上から 1 行目、左から 2 列目にあります。
入力例 2
1000000000 1000000000 10 1 1 10 10 100 100 1000 1000 10000 10000 100000 100000 1000000 1000000 10000000 10000000 100000000 100000000 1000000000 1000000000
出力例 2
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
Score : 300 points
Problem Statement
We have HW cards arranged in a matrix with H rows and W columns.
For each i=1, \ldots, N, the card at the A_i-th row from the top and B_i-th column from the left has a number i written on it. The other HW-N cards have nothing written on them.
We will repeat the following two kinds of operations on these cards as long as we can.
- If there is a row without a numbered card, remove all the cards in that row and fill the gap by shifting the remaining cards upward.
- If there is a column without a numbered card, remove all the cards in that column and fill the gap by shifting the remaining cards to the left.
Find the position of each numbered card after the end of the process above. It can be proved that these positions are uniquely determined without depending on the order in which the operations are done.
Constraints
- 1 \leq H,W \leq 10^9
- 1 \leq N \leq \min(10^5,HW)
- 1 \leq A_i \leq H
- 1 \leq B_i \leq W
- All pairs (A_i,B_i) are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W N A_1 B_1 \vdots A_N B_N
Output
Print N lines.
If, after the end of the process, the card with the number i is at the C_i-th row from the top and D_i-th column from the left, the i-th line should contain C_i and D_i in this order with a space between them.
Sample Input 1
4 5 2 3 2 2 5
Sample Output 1
2 1 1 2
Let * represent a card with nothing written on it. The initial arrangement of cards is:
***** ****2 *1*** *****
After the end of the process, they will be arranged as follows:
*2 1*
Here, the card with 1 is at the 2-nd row from the top and 1-st column from the left, and the card with 2 is at the 1-st row from the top and 2-nd column from the left.
Sample Input 2
1000000000 1000000000 10 1 1 10 10 100 100 1000 1000 10000 10000 100000 100000 1000000 1000000 10000000 10000000 100000000 100000000 1000000000 1000000000
Sample Output 2
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 N,Q と、長さ N の英小文字からなる文字列 S が与えられます。
以下で説明されるクエリを Q 個処理してください。クエリは次の 2 種類のいずれかです。
1 x: 「S の末尾の文字を削除し、先頭に挿入する」という操作を x 回連続で行う。2 x: S の x 番目の文字を出力する。
制約
- 2 \le N \le 5 \times 10^5
- 1 \le Q \le 5 \times 10^5
- 1 \le x \le N
- |S|=N
- S は英小文字からなる。
2 xの形式のクエリが 1 個以上与えられる。- N,Q,x はすべて整数。
入力
入力は以下の形式で標準入力から与えられる。
N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
それぞれのクエリは以下の形式で与えられる。ここで、t は 1 または 2 である。
t x
出力
2 x の形式の各クエリについて、答えを一行に出力せよ。
入力例 1
3 3 abc 2 2 1 1 2 2
出力例 1
b a
1 個目のクエリのとき、S は abc なので 2 文字目の b を出力します。
2 個目のクエリのとき、S は abc から cab に変わります。
3 個目のクエリのとき、S は cab なので 2 文字目の a を出力します。
入力例 2
10 8 dsuccxulnl 2 4 2 7 1 2 2 7 1 1 1 2 1 3 2 5
出力例 2
c u c u
Score : 300 points
Problem Statement
You are given positive integers N and Q, and a string S of length N consisting of lowercase English letters.
Process Q queries. Each query is of one of the following two types.
1 x: Perform the following x times in a row: delete the last character of S and append it to the beginning.2 x: Print the x-th character of S.
Constraints
- 2 \le N \le 5 \times 10^5
- 1 \le Q \le 5 \times 10^5
- 1 \le x \le N
- |S|=N
- S consists of lowercase English letters.
- At least one query in the format
2 x. - N, Q, x are all integers.
Input
Input is given from Standard Input in the following format:
N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each query is in the following format, where t is 1 or 2:
t x
Output
For each query in the format 2 x, print the answer in a single line.
Sample Input 1
3 3 abc 2 2 1 1 2 2
Sample Output 1
b a
In the 1-st query, S is abc, so the 2-nd character b should be printed.
In the 2-nd query, S is changed from abc to cab.
In the 3-rd query, S is cab, so the 2-nd character a should be printed.
Sample Input 2
10 8 dsuccxulnl 2 4 2 7 1 2 2 7 1 1 1 2 1 3 2 5
Sample Output 2
c u c u
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
文字列 S があり、初め S= 1 です。
以下の形式のクエリが Q 個与えられるので順に処理してください。
1 x: S の末尾に数字 x を追加する2: S の先頭の数字を削除する3: S を十進数表記の数とみなした値を 998244353 で割った余りを出力する
制約
- 1 \leq Q \leq 6 \times 10^5
- 1 番目の形式のクエリについて、x \in \{1,2,3,4,5,6,7,8,9\}
- 2 番目の形式のクエリは S が 2 文字以上の時にのみ与えられる
- 3 番目の形式のクエリが 1 個以上存在する
入力
入力は以下の形式で標準入力から与えられる。
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
ただし \mathrm{query}_i は i 番目のクエリを表し、以下のいずれかの形式である。
1 x
2
3
出力
3 番目の形式のクエリの個数を q として、q 行出力せよ。i (1 \leq i \leq q) 行目には i 番目の 3 番目の形式のクエリに対する出力をせよ。
入力例 1
3 3 1 2 3
出力例 1
1 12
1 番目のクエリにおいて、S は 1 なので ( 1 を 998244353 で割った余りに等しい) 1 を出力します。
2 番目のクエリにおいて、S は 12 になります。
3 番目のクエリにおいて、S は 12 なので ( 12 を 998244353 で割った余りに等しい) 12 を出力します。
入力例 2
3 1 5 2 3
出力例 2
5
入力例 3
11 1 9 1 9 1 8 1 2 1 4 1 4 1 3 1 5 1 3 2 3
出力例 3
0
出力されるべき値は 998244353 で割った余りであることに注意してください。
Score : 400 points
Problem Statement
We have a string S. Initially, S= 1.
Process Q queries in the following formats in order.
1 x: Append a digit x at the end of S.2: Delete the digit at the beginning of S.3: Print the number represented by S in decimal, modulo 998244353.
Constraints
- 1 \leq Q \leq 6 \times 10^5
- For each query in the first format, x \in \{1,2,3,4,5,6,7,8,9\}.
- A query in the second format is given only if S has a length of 2 or greater.
- There is at least one query in the third format.
Input
The input is given from Standard Input in the following format:
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_i denotes the i-th query, which is in one of the following formats:
1 x
2
3
Output
Print q lines, where q is the number of queries in the third format. The i-th line (1 \leq i \leq q) should correspond to the i-th query in the third format.
Sample Input 1
3 3 1 2 3
Sample Output 1
1 12
In the first query, S is 1, so you should print 1 modulo 998244353, that is, 1.
In the second query, S becomes 12.
In the third query, S is 12, so you should print 12 modulo 998244353, that is, 12.
Sample Input 2
3 1 5 2 3
Sample Output 2
5
Sample Input 3
11 1 9 1 9 1 8 1 2 1 4 1 4 1 3 1 5 1 3 2 3
Sample Output 3
0
Be sure to print numbers modulo 998244353.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
AtCoder 国には駅 1, 駅 2,\ldots, 駅 N の N 個の駅があります。
AtCoder 国に存在する電車の情報が M 個与えられます。 i 番目 (1\leq i\leq M) の情報は正整数の 6 つ組 (l _ i,d _ i,k _ i,c _ i,A _ i,B _ i) で表され、次のような情報に対応しています。
- t=l _ i,l _ i+d _ i,l _ i+2d _ i,\ldots,l _ i+(k _ i-1)d _ i それぞれについて、次のような電車が存在する。
- 時刻 t に 駅 A _ i を出発し、時刻 t+c _ i に駅 B _ i に到着する。
これらの情報にあてはまらない電車は存在せず、電車以外の方法である駅から異なる駅へ移動することはできません。
また、乗り換えにかかる時間は無視できるとします。
駅 S から駅 N に到着できる最終時刻を f(S) とします。
より厳密には、整数の 4 つ組の列 \big((t _ i,c _ i,A _ i,B _ i)\big) _ {i=1,2,\ldots,k} であって、次のすべての条件を満たすものが存在するような t の最大値を f(S) とします。
- t\leq t _ 1
- A _ 1=S,B _ k=N
- すべての 1\leq i\lt k について、B _ i=A _ {i+1}
- すべての 1\leq i\leq k について、時刻 t _ i に駅 A _ i を出発して時刻 t _ i+c _ i に駅 B _ i に到着する電車が存在する。
- すべての 1\leq i\lt k について、t _ i+c _ i\leq t _ {i+1}
ただし、そのような t が存在しないとき f(S)=-\infty とします。
f(1),f(2),\ldots,f(N-1) を求めてください。
制約
- 2\leq N\leq2\times10 ^ 5
- 1\leq M\leq2\times10 ^ 5
- 1\leq l _ i,d _ i,k _ i,c _ i\leq10 ^ 9\ (1\leq i\leq M)
- 1\leq A _ i,B _ i\leq N\ (1\leq i\leq M)
- A _ i\neq B _ i\ (1\leq i\leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M l _ 1 d _ 1 k _ 1 c _ 1 A _ 1 B _ 1 l _ 2 d _ 2 k _ 2 c _ 2 A _ 2 B _ 2 \vdots l _ M d _ M k _ M c _ M A _ M B _ M
出力
N-1 行出力せよ。
k 行目には f(k)\neq-\infty ならば f(k) を、f(k)=-\infty ならば Unreachable を出力せよ。
入力例 1
6 7 10 5 10 3 1 3 13 5 10 2 3 4 15 5 10 7 4 6 3 10 2 4 2 5 7 10 2 3 5 6 5 3 18 2 2 3 6 3 20 4 2 1
出力例 1
55 56 58 60 17
AtCoder 国に走っている電車は以下の図のようになります(発着時間の情報は図には含まれていません)。

駅 2 から駅 6 に到着できる最終時刻について考えます。 次の図のように、駅 2 を時刻 56 に出発して駅 2\rightarrow 駅 3\rightarrow 駅 4\rightarrow 駅 6 のように移動することで駅 6 に到着することができます。

駅 2 を時刻 56 より遅く出発して駅 6 に到着することはできないため、f(2)=56 です。
入力例 2
5 5 1000000000 1000000000 1000000000 1000000000 1 5 5 9 2 6 2 3 10 4 1 6 2 3 1 1 1 1 3 5 3 1 4 1 5 1
出力例 2
1000000000000000000 Unreachable 1 Unreachable
駅 1 を時刻 10 ^ {18} に出発して駅 5 に時刻 10 ^ {18}+10 ^ 9 に到着するような電車が存在します。それ以降に駅 1 を出発する電車はないため、f(1)=10 ^ {18} です。 このように、答えが 32\operatorname{bit} 整数におさまらない場合もあります。
また、時刻 14 に駅 2 を出発して時刻 20 に駅 3 に到着するような電車は 2 番目の情報と 3 番目の情報の両方で存在が保証されています。 このように、複数の情報に重複している電車もあります。
入力例 3
16 20 4018 9698 2850 3026 8 11 2310 7571 7732 1862 13 14 2440 2121 20 1849 11 16 2560 5115 190 3655 5 16 1936 6664 39 8822 4 16 7597 8325 20 7576 12 5 5396 1088 540 7765 15 1 3226 88 6988 2504 13 5 1838 7490 63 4098 8 3 1456 5042 4 2815 14 7 3762 6803 5054 6994 10 9 9526 6001 61 8025 7 8 5176 6747 107 3403 1 5 2014 5533 2031 8127 8 11 8102 5878 58 9548 9 10 3788 174 3088 5950 3 13 7778 5389 100 9003 10 15 556 9425 9458 109 3 11 5725 7937 10 3282 2 9 6951 7211 8590 1994 15 12
出力例 3
720358 77158 540926 255168 969295 Unreachable 369586 466218 343148 541289 42739 165772 618082 16582 591828
Score: 450 points
Problem Statement
In the country of AtCoder, there are N stations: station 1, station 2, \ldots, station N.
You are given M pieces of information about trains in the country. The i-th piece of information (1\leq i\leq M) is represented by a tuple of six positive integers (l _ i,d _ i,k _ i,c _ i,A _ i,B _ i), which corresponds to the following information:
- For each t=l _ i,l _ i+d _ i,l _ i+2d _ i,\ldots,l _ i+(k _ i-1)d _ i, there is a train as follows:
- The train departs from station A _ i at time t and arrives at station B _ i at time t+c _ i.
No trains exist other than those described by this information, and it is impossible to move from one station to another by any means other than by train.
Also, assume that the time required for transfers is negligible.
Let f(S) be the latest time at which one can arrive at station N from station S.
More precisely, f(S) is defined as the maximum value of t for which there is a sequence of tuples of four integers \big((t _ i,c _ i,A _ i,B _ i)\big) _ {i=1,2,\ldots,k} that satisfies all of the following conditions:
- t\leq t _ 1
- A _ 1=S,B _ k=N
- B _ i=A _ {i+1} for all 1\leq i\lt k,
- For all 1\leq i\leq k, there is a train that departs from station A _ i at time t _ i and arrives at station B _ i at time t _ i+c _ i.
- t _ i+c _ i\leq t _ {i+1} for all 1\leq i\lt k.
If no such t exists, set f(S)=-\infty.
Find f(1),f(2),\ldots,f(N-1).
Constraints
- 2\leq N\leq2\times10 ^ 5
- 1\leq M\leq2\times10 ^ 5
- 1\leq l _ i,d _ i,k _ i,c _ i\leq10 ^ 9\ (1\leq i\leq M)
- 1\leq A _ i,B _ i\leq N\ (1\leq i\leq M)
- A _ i\neq B _ i\ (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 d _ 1 k _ 1 c _ 1 A _ 1 B _ 1 l _ 2 d _ 2 k _ 2 c _ 2 A _ 2 B _ 2 \vdots l _ M d _ M k _ M c _ M A _ M B _ M
Output
Print N-1 lines.
The k-th line should contain f(k) if f(k)\neq-\infty, and Unreachable if f(k)=-\infty.
Sample Input 1
6 7 10 5 10 3 1 3 13 5 10 2 3 4 15 5 10 7 4 6 3 10 2 4 2 5 7 10 2 3 5 6 5 3 18 2 2 3 6 3 20 4 2 1
Sample Output 1
55 56 58 60 17
The following diagram shows the trains running in the country (information about arrival and departure times is omitted).

Consider the latest time at which one can arrive at station 6 from station 2. As shown in the following diagram, one can arrive at station 6 by departing from station 2 at time 56 and moving as station 2\rightarrow station 3\rightarrow station 4\rightarrow station 6.

It is impossible to depart from station 2 after time 56 and arrive at station 6, so f(2)=56.
Sample Input 2
5 5 1000000000 1000000000 1000000000 1000000000 1 5 5 9 2 6 2 3 10 4 1 6 2 3 1 1 1 1 3 5 3 1 4 1 5 1
Sample Output 2
1000000000000000000 Unreachable 1 Unreachable
There is a train that departs from station 1 at time 10 ^ {18} and arrives at station 5 at time 10 ^ {18}+10 ^ 9. There are no trains departing from station 1 after that time, so f(1)=10 ^ {18}. As seen here, the answer may not fit within a 32\operatorname{bit} integer.
Also, both the second and third pieces of information guarantee that there is a train that departs from station 2 at time 14 and arrives at station 3 at time 20. As seen here, some trains may appear in multiple pieces of information.
Sample Input 3
16 20 4018 9698 2850 3026 8 11 2310 7571 7732 1862 13 14 2440 2121 20 1849 11 16 2560 5115 190 3655 5 16 1936 6664 39 8822 4 16 7597 8325 20 7576 12 5 5396 1088 540 7765 15 1 3226 88 6988 2504 13 5 1838 7490 63 4098 8 3 1456 5042 4 2815 14 7 3762 6803 5054 6994 10 9 9526 6001 61 8025 7 8 5176 6747 107 3403 1 5 2014 5533 2031 8127 8 11 8102 5878 58 9548 9 10 3788 174 3088 5950 3 13 7778 5389 100 9003 10 15 556 9425 9458 109 3 11 5725 7937 10 3282 2 9 6951 7211 8590 1994 15 12
Sample Output 3
720358 77158 540926 255168 969295 Unreachable 369586 466218 343148 541289 42739 165772 618082 16582 591828
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
あなたとジャッジは下記の手順を行います。 手順はフェイズ 1 とフェイズ 2 からなり、まずフェイズ 1 を行った直後、続けてフェイズ 2 を行います。
(フェイズ 1 )
- ジャッジから整数 N が与えられる。
- あなたは 1 以上 50000 以下の整数 M を出力する。
- さらにあなたは、すべての i = 1, 2, \ldots, M について 1 \leq l_i \leq r_i \leq N を満たす、M 個の整数の組 (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) を出力する(M 個の整数の組が相異なる必要はない)。
(フェイズ 2 )
- ジャッジから整数 Q が与えられる。
- その後、あなたとジャッジは下記の手順を Q 回繰り返す。
- ジャッジからクエリとして 2 つの整数 L, R が与えられる。
- それに対する応答として、あなたは 1 以上 M 以下の 2 つの整数 a, b を出力する( a = b でもよい)。
このとき、a と b は下記の条件を満たさなければならない。もし満たさなかった場合は不正解となる。
- 集合 \lbrace l_a, l_a+1, \ldots, r_a\rbrace と集合 \lbrace l_b, l_b+1, \ldots, r_b\rbrace の和集合が、集合 \lbrace L, L+1, \ldots, R\rbrace と一致する。
上記の手順を行った後、直ちにプログラムを終了することで正解となります。
制約
- 1 \leq N \leq 4000
- 1 \leq Q \leq 10^5
- 1 \leq L \leq R \leq N
- 入力はすべて整数
入出力
この問題はインタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
(フェイズ 1 )
- まず、N が入力から与えられます。
- 次に、1 以上 50000 以下の整数 M を出力してください。
- その後、M 回にわたって (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) を出力してください。 具体的には、i = 1, 2, \ldots, M について、i 回目の出力では (l_i, r_i) を下記の形式で出力してください。
l_i r_i
(フェイズ 2 )
- まず、Q が入力から与えられます。
- 各クエリでは、クエリを表す整数 L, R が下記の形式で与えられます。
L R
- 各クエリに対する応答では、2 つの整数 a, b を下記の形式で出力してください。
a b
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。 特に、プログラムの実行中に実行時エラーが起こった場合に、ジャッジ結果が ではなく や TLE になる可能性があることに注意してください。
- フェイズ 2 を終了したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- フェイズ 2 で与えられる L, R は、あなたがフェイズ 1 で出力した (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) に応じて決定されます。
入出力例
以下は、N = 4, Q = 4 の場合の入出力例です。
| 入力 | 出力 | 説明 |
|---|---|---|
4 |
N が与えられます。 | |
6 |
M を出力します。 | |
3 3 |
(l_1, r_1) = (3, 3) を出力します。 | |
4 4 |
(l_2, r_2) = (4, 4) を出力します。 | |
1 1 |
(l_3, r_3) = (1, 1) を出力します。 | |
2 4 |
(l_4, r_4) = (2, 4) を出力します。 | |
1 3 |
(l_5, r_5) = (1, 3) を出力します。 | |
2 2 |
(l_6, r_6) = (2, 2) を出力します。 | |
4 |
Q が与えられます。 | |
1 3 |
1 個目のクエリとして L = 1, R = 3 が与えられます。 | |
1 5 |
1 個目のクエリに対する応答として a = 1, b = 5 を出力します。 | |
3 4 |
2 個目のクエリとして L = 3, R = 4 が与えられます。 | |
2 1 |
2 個目のクエリに対する応答として a = 2, b = 1 を出力します。 | |
2 4 |
3 個目のクエリとして L = 2, R = 4 が与えられます。 | |
4 4 |
3 個目のクエリに対する応答として a = 4, b = 4 を出力します。 | |
1 1 |
4 個目のクエリとして L = 1, R = 1 が与えられます。 | |
3 3 |
4 個目のクエリに対する応答として a = 3, b = 3 を出力します。 | |
Score : 500 points
Problem Statement
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
You and the judge will follow the procedure below. The procedure consists of phases 1 and 2; phase 1 is immediately followed by phase 2.
(Phase 1)
- The judge gives you an integer N.
- You print an integer M between 1 and 50000, inclusive.
- You also print M pairs of integers (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) such that 1 \leq l_i \leq r_i \leq N for every i = 1, 2, \ldots, M (the M pairs do not have to be distinct).
(Phase 2)
- The judge gives you an integer Q.
- You and the judge repeats the following Q times.
- The judge gives you two integers L and R as a query.
- You respond with two integers a and b between 1 and M, inclusive (possibly with a = b).
Here, a and b must satisfy the condition below. Otherwise, your submission will be judged incorrect.
- The union of the set \lbrace l_a, l_a+1, \ldots, r_a\rbrace and the set \lbrace l_b, l_b+1, \ldots, r_b\rbrace equals the set \lbrace L, L+1, \ldots, R\rbrace.
After the procedure above, terminate the program immediately to be judged correct.
Constraints
- 1 \leq N \leq 4000
- 1 \leq Q \leq 10^5
- 1 \leq L \leq R \leq N
- All values in the input are integers.
Input and Output
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
(Phase 1)
- First, N is given from the input.
- Next, an integer M between 1 and 50000, inclusive, should be printed.
- Then, (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) should be printed, one at a time. Specifically, for each i = 1, 2, \ldots, M, the i-th output should be (l_i, r_i) in the following format:
l_i r_i
(Phase 2)
- First, Q is given from the input.
- In each query, integers L and R representing the query are given in the following format:
L R
- In response to each query, two integers a and b should be printed in the following format:
a b
Cautions
- At the end of each output, print a newline and flush Standard Output. Otherwise, you may get the TLE verdict.
- If your program prints a malformed output or quits prematurely, the verdict will be indeterminate. Particularly, note that in case of a runtime error, the verdict may be or TLE instead of .
- After phase 2, immediately terminate the program. Otherwise, the verdict will be indeterminate.
- L and R given in phase 2 will be decided according to (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) you print in phase 1.
Sample Interaction
Below is a sample interaction with N = 4 and Q = 4.
| Input | Output | Description |
|---|---|---|
4 |
N is given. | |
6 |
You print M. | |
3 3 |
You print (l_1, r_1) = (3, 3). | |
4 4 |
You print (l_2, r_2) = (4, 4). | |
1 1 |
You print (l_3, r_3) = (1, 1). | |
2 4 |
You print (l_4, r_4) = (2, 4). | |
1 3 |
You print (l_5, r_5) = (1, 3). | |
2 2 |
You print (l_6, r_6) = (2, 2). | |
4 |
Q is given. | |
1 3 |
As the first query, L = 1 and R = 3 are given. | |
1 5 |
You respond with a = 1 and b = 5. | |
3 4 |
As the second query, L = 3 and R = 4 are given. | |
2 1 |
You respond with a = 2 and b = 1. | |
2 4 |
As the third query, L = 2 and R = 4 are given. | |
4 4 |
You respond with a = 4 and b = 4. | |
1 1 |
As the fourth query, L = 1 and R = 1 are given. | |
3 3 |
You respond with a = 3 and b = 3. | |