実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君と青木君は 2 人で次の対戦ゲームをします。
高橋君が先手でゲームを始め、ゲームが終了するまでの間、 2 人は交互に 1 以上 2N+1 以下の整数を 1 つずつ宣言します。 どちらかが一度でも宣言した整数は、それ以降どちらも二度と宣言することが出来ません。 先に整数を宣言することが出来なくなった方のプレイヤーの負けとなり、負けなかった方のプレイヤーの勝ちとなります。
このゲームでは必ず高橋君が勝ちます。 高橋君の立場で実際にゲームを行い、ゲームに勝ってください。
制約
- 1 \leq N \leq 1000
- N は整数
入出力
この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジプログラムが入出力を介して対話を行う形式の問題)です。
あなたのプログラムが高橋君の立場で、ジャッジプログラムが青木君の立場でゲームを行います。
まず、あなたのプログラムに標準入力から正の整数 N が与えられます。 その後、ゲームが終了するまで下記の手順を繰り返します。
- あなたのプログラムが、高橋君が宣言する整数として、1 以上 2N+1 以下の整数を標準出力に出力します。(どちらかのプレイヤーによってすでに宣言されている整数を出力することは出来ません。)
- ジャッジプログラムによって、青木君が宣言する整数があなたのプログラムに標準入力から与えられます。(どちらかのプレイヤーによってすでに宣言されている整数が入力されることはありません。) ただし、青木君が宣言できる整数が残っていない場合は、代わりに 0 が与えられ高橋君の勝ちでゲームが終了します。
注意点
- 出力を行うたびに標準出力をflushしてください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 高橋君の勝ちでゲームが終了したあと、あなたのプログラムは直ちに終了しなければなりません。そうしなかった場合、ジャッジ結果が AC とならない可能性があります。
- ゲームの途中で不正な出力を行った場合(例えば、すでにどちらかのプレイヤーによって宣言されている整数を出力した場合)は不正解となりますが、そのときのジャッジ結果は不定です。WA になるとは限りません。
入出力例
入力 | 出力 | 説明 |
---|---|---|
2 | まず整数 N が与えられます。 | |
1 | 高橋君が 1 を宣言します。 | |
3 | 青木君が 3 を宣言します。 | |
2 | 高橋君が 2 を宣言します。 | |
4 | 青木君が 4 を宣言します。 | |
5 | 高橋君が 5 を宣言します。 | |
0 | 青木君が宣言できる整数が残っていないため、高橋君の勝ちでゲームが終了します。 |
Score : 300 points
Problem Statement
Takahashi and Aoki will play the following game against each other.
Starting from Takahashi, the two alternatingly declare an integer between 1 and 2N+1 (inclusive) until the game ends. Any integer declared by either player cannot be declared by either player again. The player who is no longer able to declare an integer loses; the player who didn't lose wins.
In this game, Takahashi will always win. Your task is to actually play the game on behalf of Takahashi and win the game.
Constraints
- 1 \leq N \leq 1000
- N is an integer.
Input and Output
This task is an interactive task (in which your program and the judge program interact with each other via inputs and outputs).
Your program plays the game on behalf of Takahashi, and the judge program plays the game on behalf of Aoki.
First, your program is given a positive integer N from Standard Input. Then, the following procedures are repeated until the game ends.
- Your program outputs an integer between 1 and 2N+1 (inclusive) to Standard Output, which defines the integer that Takahashi declares. (You cannot output an integer that is already declared by either player.)
- The integer that Aoki declares is given by the judge program to your program from Standard Input. (No integer that is already declared by either player will be given.) If Aoki has no more integer to declare, 0 is given instead, which means that the game ended and Takahashi won.
Notes
- After each output, you must flush Standard Output. Otherwise, you may get TLE.
- After the game ended and Takahashi won, the program must be terminated immediately. Otherwise, the judge does not necessarily give AC.
- If your program outputs something that violates the rules of the game (such as an integer that has already been declared by either player), your answer is considered incorrect. In such case, the verdict is indeterminate. It does not necessarily give WA.
Sample Input and Output
Input | Output | Description |
---|---|---|
2 | First, an integer N is given. | |
1 | Takahashi declares an integer 1. | |
3 | Aoki declares an integer 3. | |
2 | Takahashi declares an integer 2. | |
4 | Aoki declares an integer 4. | |
5 | Takahashi declares an integer 5. | |
0 | Aoki has no more integer to declare, so Takahashi wins, and the game ends. |
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
以下の条件を満たす正整数 x を 321-like Number と呼びます。 この定義は A 問題と同様です。
- x の各桁を上から見ると狭義単調減少になっている。
- すなわち、x が d 桁の整数だとすると、 1 \le i < d を満たす全ての整数 i について以下の条件を満たす。
- ( x の上から i 桁目 ) > ( x の上から i+1 桁目 )
なお、 1 桁の正整数は必ず 321-like Number であることに注意してください。
例えば、 321,96410,1 は 321-like Number ですが、 123,2109,86411 は 321-like Number ではありません。
K 番目に小さい 321-like Number を求めてください。
制約
- 入力は全て整数
- 1 \le K
- 321-like Number は K 個以上存在する
入力
入力は以下の形式で標準入力から与えられる。
K
出力
K 番目に小さい 321-like Number を整数として出力せよ。
入力例 1
15
出力例 1
32
321-like Number は小さいものから順に (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) です。
このうち 15 番目に小さいものは 32 です。
入力例 2
321
出力例 2
9610
入力例 3
777
出力例 3
983210
Score : 300 points
Problem Statement
A positive integer x is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A.
- The digits of x are strictly decreasing from top to bottom.
- In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
- (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).
Note that all one-digit positive integers are 321-like Numbers.
For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.
Find the K-th smallest 321-like Number.
Constraints
- All input values are integers.
- 1 \le K
- At least K 321-like Numbers exist.
Input
The input is given from Standard Input in the following format:
K
Output
Print the K-th smallest 321-like Number as an integer.
Sample Input 1
15
Sample Output 1
32
The 321-like Numbers are (1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,40,\dots) from smallest to largest.
The 15-th smallest of them is 32.
Sample Input 2
321
Sample Output 2
9610
Sample Input 3
777
Sample Output 3
983210
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 台のソリがあり、各ソリには 1,2,\ldots, N の番号がつけられています。
ソリ i を引くために必要なトナカイは R_i 匹です。
また、各トナカイが引けるソリは高々 1 台です。より厳密には、m 台のソリ i_1, i_2, \ldots, i_m を引くために必要なトナカイは \sum_{k=1}^{m} R_{i_k} 匹です。
以下の形式のクエリが Q 個与えられるので、答えを求めてください。
- 整数 X が与えられる。トナカイが X 匹いるときに最大で何台のソリを引けるか求めよ。
制約
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq R_i \leq 10^9
- 1 \leq X \leq 2 \times 10^{14}
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q R_1 R_2 \ldots R_N \text{query}_1 \text{query}_2 \vdots \text{query}_Q
各クエリは次の形式で与えられる。
X
出力
Q 行出力せよ。
i 行目には i 個目のクエリに対する答えを出力せよ。
入力例 1
4 3 5 3 11 8 16 7 1000
出力例 1
3 1 4
トナカイが 16 匹いるとき、ソリ 1,2,4 を引くことができます。
16 匹のトナカイで 4 台のソリを引くことはできないので、クエリ 1 の答えは 3 となります。
入力例 2
6 6 1 2 3 4 5 6 1 2 3 4 5 6
出力例 2
1 1 2 2 2 3
入力例 3
2 2 1000000000 1000000000 200000000000000 1
出力例 3
2 0
Score : 400 points
Problem Statement
There are N sleighs numbered 1,2,\ldots, N.
R_i reindeer are required to pull sleigh i.
Additionally, each reindeer can pull at most one sleigh. More precisely, \sum_{k=1}^{m} R_{i_k} reindeer are required to pull m sleighs i_1, i_2, \ldots, i_m.
Find the answer to Q queries of the following form:
- You are given an integer X. Determine the maximum number of sleighs that can be pulled when there are X reindeer.
Constraints
- 1 \leq N, Q \leq 2 \times 10^5
- 1 \leq R_i \leq 10^9
- 1 \leq X \leq 2 \times 10^{14}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q R_1 R_2 \ldots R_N \text{query}_1 \text{query}_2 \vdots \text{query}_Q
Each query is given in the following format:
X
Output
Print Q lines.
The i-th line should contain the answer to the i-th query.
Sample Input 1
4 3 5 3 11 8 16 7 1000
Sample Output 1
3 1 4
When there are 16 reindeer, sleighs 1,2,4 can be pulled.
It is impossible to pull four sleighs with 16 reindeer, so the answer to query 1 is 3.
Sample Input 2
6 6 1 2 3 4 5 6 1 2 3 4 5 6
Sample Output 2
1 1 2 2 2 3
Sample Input 3
2 2 1000000000 1000000000 200000000000000 1
Sample Output 3
2 0
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
2 次元平面の原点に高橋君がいます。
高橋君はこれから、ワープを N 回繰り返します。各ワープでは、以下の 3 つのうちいずれか 1 つを行います。
- 現在いる座標 (x,y) から (x+A,y+B) に移動する
- 現在いる座標 (x,y) から (x+C,y+D) に移動する
- 現在いる座標 (x,y) から (x+E,y+F) に移動する
平面上の M 箇所 (X_1,Y_1),\ldots,(X_M,Y_M) には障害物があり、これらの座標に移動することはできません。
N 回のワープによる移動経路として考えられるものは何通りですか? 998244353 で割ったあまりを求めてください。
制約
- 1 \leq N \leq 300
- 0 \leq M \leq 10^5
- -10^9 \leq A,B,C,D,E,F \leq 10^9
- (A,B),(C,D),(E,F) は相異なる
- -10^9 \leq X_i,Y_i \leq 10^9
- (X_i,Y_i)\neq(0,0)
- (X_i,Y_i) は相異なる
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A B C D E F X_1 Y_1 X_2 Y_2 \vdots X_M Y_M
出力
答えを出力せよ。
入力例 1
2 2 1 1 1 2 1 3 1 2 2 2
出力例 1
5
以下の 5 通りが考えられます。
- (0,0)\to(1,1)\to(2,3)
- (0,0)\to(1,1)\to(2,4)
- (0,0)\to(1,3)\to(2,4)
- (0,0)\to(1,3)\to(2,5)
- (0,0)\to(1,3)\to(2,6)
入力例 2
10 3 -1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000
出力例 2
0
入力例 3
300 0 0 0 1 0 0 1
出力例 3
292172978
Score : 500 points
Problem Statement
Takahashi is at the origin of a two-dimensional plane.
Takahashi will repeat teleporting N times. In each teleportation, he makes one of the following moves:
- Move from the current coordinates (x,y) to (x+A,y+B)
- Move from the current coordinates (x,y) to (x+C,y+D)
- Move from the current coordinates (x,y) to (x+E,y+F)
There are obstacles on M points (X_1,Y_1),\ldots,(X_M,Y_M) on the plane; he cannot teleport to these coordinates.
How many paths are there resulting from the N teleportations? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 300
- 0 \leq M \leq 10^5
- -10^9 \leq A,B,C,D,E,F \leq 10^9
- (A,B), (C,D), and (E,F) are distinct.
- -10^9 \leq X_i,Y_i \leq 10^9
- (X_i,Y_i)\neq(0,0)
- (X_i,Y_i) are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A B C D E F X_1 Y_1 X_2 Y_2 \vdots X_M Y_M
Output
Print the answer.
Sample Input 1
2 2 1 1 1 2 1 3 1 2 2 2
Sample Output 1
5
The following 5 paths are possible:
- (0,0)\to(1,1)\to(2,3)
- (0,0)\to(1,1)\to(2,4)
- (0,0)\to(1,3)\to(2,4)
- (0,0)\to(1,3)\to(2,5)
- (0,0)\to(1,3)\to(2,6)
Sample Input 2
10 3 -1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000
Sample Output 2
0
Sample Input 3
300 0 0 0 1 0 0 1
Sample Output 3
292172978
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
文字列 S が与えられます。高橋君はこの文字列から以下の手順にしたがって新しい文字列 T を作ります。
- まず、S の文字のうちの一つ以上に印をつける。ただし、印をつけた文字どうしが隣り合ってはならない。
- 次に、印がついていない文字を全て削除する。
- 最後に、残った文字列を T とする。ただし、この時に文字を並び替えてはならない。
T としてありうる文字列は何種類ありますか? (10^9 + 7) で割ったあまりを求めてください。
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T としてありうる文字列の種類数を (10^9 + 7) で割ったあまりを出力せよ。
入力例 1
abc
出力例 1
4
T としてありうるものは a
、 b
、 c
、 ac
の 4 つです。
S の 1 文字目のみに印をつけたとき T は a
、
S の 2 文字目のみに印をつけたとき T は b
、
S の 3 文字目のみに印をつけたとき T は c
、
S の 1 文字目と 3 文字目のみに印をつけたとき T は ac
、
となります。例えば 1 文字目と 2 文字目の両方に印をつけることはできないことに注意してください。
入力例 2
aa
出力例 2
1
T としてありうるものは a
のみです。
印をつけた位置が異なっていても T が同じ文字列となる可能性があることに注意してください。
入力例 3
acba
出力例 3
6
T としてありうるものは a
、 b
、 c
、 aa
、 ab
、 ca
の 6 つです。
入力例 4
chokudai
出力例 4
54
Score : 500 points
Problem Statement
Given is a string S. From this string, Takahashi will make a new string T as follows.
- First, mark one or more characters in S. Here, no two marked characters should be adjacent.
- Next, delete all unmarked characters.
- Finally, let T be the remaining string. Here, it is forbidden to change the order of the characters.
How many strings are there that can be obtained as T? Find the count modulo (10^9 + 7).
Constraints
- S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained as T, modulo (10^9 + 7).
Sample Input 1
abc
Sample Output 1
4
There are four strings that can be obtained as T: a
, b
, c
, and ac
.
Marking the first character of S yields a
;
marking the second character of S yields b
;
marking the third character of S yields c
;
marking the first and third characters of S yields ac
.
Note that it is forbidden to, for example, mark both the first and second characters.
Sample Input 2
aa
Sample Output 2
1
There is just one string that can be obtained as T, which is a
.
Note that marking different positions may result in the same string.
Sample Input 3
acba
Sample Output 3
6
There are six strings that can be obtained as T: a
, b
, c
, aa
, ab
, and ca
.
Sample Input 4
chokudai
Sample Output 4
54