Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
0 以上 9999 以下の整数 N が与えられます。
N の先頭に必要なだけ 0 をつけ、4 桁の文字列にしたものを出力してください。
制約
- 0 \leq N \leq 9999
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
321
出力例 1
0321
321 は 3 桁なので、先頭に 1 つ 0 をつけると 4 桁になります。
入力例 2
7777
出力例 2
7777
入力例 3
1
出力例 3
0001
Score : 100 points
Problem Statement
You are given an integer N between 0 and 9999 (inclusive).
Print it as a four-digit string after appending to it the necessary number of leading zeros.
Constraints
- 0 \leq N \leq 9999
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
321
Sample Output 1
0321
321 has three digits, so we need to add one leading zero to it to make it have four digits.
Sample Input 2
7777
Sample Output 2
7777
Sample Input 3
1
Sample Output 3
0001
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 個の整数の 2 つ組 (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N) が与えられます。 各 i = 1, 2, \ldots, N について、A_i + B_i を出力してください。
制約
- 1 \leq N \leq 1000
- -10^9 \leq A_i, B_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には A_i+B_i を出力せよ。
入力例 1
4 3 5 2 -6 -5 0 314159265 123456789
出力例 1
8 -4 -5 437616054
- 1 行目には、A_1 + B_1 = 3 + 5 = 8 を、
- 2 行目には、A_2 + B_2 = 2 + (-6) = -4 を、
- 3 行目には、A_3 + B_3 = (-5) + 0 = -5 を、
- 4 行目には、A_4 + B_4 = 314159265 + 123456789 = 437616054 を出力します。
Score : 100 points
Problem Statement
You are given N pairs of integers: (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N). For each i = 1, 2, \ldots, N, print A_i + B_i.
Constraints
- 1 \leq N \leq 1000
- -10^9 \leq A_i, B_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain A_i+B_i.
Sample Input 1
4 3 5 2 -6 -5 0 314159265 123456789
Sample Output 1
8 -4 -5 437616054
- The first line should contain A_1 + B_1 = 3 + 5 = 8.
- The second line should contain A_2 + B_2 = 2 + (-6) = -4.
- The third line should contain A_3 + B_3 = (-5) + 0 = -5.
- The fourth line should contain A_4 + B_4 = 314159265 + 123456789 = 437616054.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
xy 平面上に 1 から N までの番号が付いた N 個の点があります。点 i は座標 (X_i, Y_i) にあり、相異なる 2 点の座標は異なります。
各点について、その点からの距離が最大である点を求めてその点の番号を出力してください。 ただし、距離が最大である点が複数ある場合はその中で最も番号が小さい点の番号を出力してください。
ここで、距離はユークリッド距離、すなわち 2 点 (x_1,y_1) と (x_2,y_2) に対し、この 2 点間の距離が \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}} であるものとして定められています。
制約
- 2 \leq N \leq 100
- -1000 \leq X_i, Y_i \leq 1000
- 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
出力
N 行出力せよ。i 行目には点 i からの距離が最大である点の番号を出力せよ。
入力例 1
4 0 0 2 4 5 0 3 4
出力例 1
3 3 1 1
以下の図のように点が並んでいます。ここで P_i は点 i を表します。
点 1 からの距離が最大である点は点 3,4 で、その中で番号が小さいのは点 3 です。
点 2 からの距離が最大である点は点 3 です。
点 3 からの距離が最大である点は点 1,2 で、その中で番号が小さいのは点 1 です。
点 4 からの距離が最大である点は点 1 です。
入力例 2
6 3 2 1 6 4 5 1 3 5 5 9 8
出力例 2
6 6 6 6 6 4
Score: 200 points
Problem Statement
On the xy-plane, there are N points with ID numbers from 1 to N. Point i is located at coordinates (X_i, Y_i), and no two points have the same coordinates.
From each point, find the farthest point and print its ID number. If multiple points are the farthest, print the smallest of the ID numbers of those points.
Here, we use the Euclidean distance: for two points (x_1,y_1) and (x_2,y_2), the distance between them is \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}}.
Constraints
- 2 \leq N \leq 100
- -1000 \leq X_i, Y_i \leq 1000
- (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
- All input values are integers.
Input
The 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 N lines. The i-th line should contain the ID number of the farthest point from point i.
Sample Input 1
4 0 0 2 4 5 0 3 4
Sample Output 1
3 3 1 1
The following figure shows the arrangement of the points. Here, P_i represents point i.
The farthest point from point 1 are points 3 and 4, and point 3 has the smaller ID number.
The farthest point from point 2 is point 3.
The farthest point from point 3 are points 1 and 2, and point 1 has the smaller ID number.
The farthest point from point 4 is point 1.
Sample Input 2
6 3 2 1 6 4 5 1 3 5 5 9 8
Sample Output 2
6 6 6 6 6 4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
次の図に示す、各マスが黒または白に塗られた縦 15 行 \times 横 15 列のグリッドにおいて、 上から R 行目、左から C 列目のマスが何色かを出力して下さい。
制約
- 1 \leq R, C \leq 15
- R, C は整数
入力
入力は以下の形式で標準入力から与えられる。
R C
出力
図のグリッドにおいて上から R 行目、左から C 列目のマスが黒色の場合は black
と、白色の場合は white
と出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
3 5
出力例 1
black
図のグリッドにおいて上から 3 行目、左から 5 列目のマスは黒色です。
よって、black
と出力します。
入力例 2
4 5
出力例 2
white
図のグリッドにおいて上から 4 行目、左から 5 列目のマスは白色です。
よって、white
と出力します。
Score : 200 points
Problem Statement
Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.
Constraints
- 1 \leq R, C \leq 15
- R and C are integers.
Input
Input is given from Standard Input in the following format:
R C
Output
In the grid above, if the color of the cell at the R-th row from the top and C-th column from the left is black, then print black
; if the cell is white, then print white
. Note that the judge is case-sensitive.
Sample Input 1
3 5
Sample Output 1
black
In the grid above, the cell at the 3-rd row from the top and 5-th column from the left is black. Thus, black
should be printed.
Sample Input 2
4 5
Sample Output 2
white
In the grid above, the cell at the 4-th row from the top and 5-th column from the left is white. Thus, white
should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 D が与えられます。
非負整数 x,y に対する |x^2+y^2-D| の最小値を求めてください。
制約
- 1\leq D \leq 2\times 10^{12}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
入力例 1
21
出力例 1
1
x=4,y=2 のとき |x^2+y^2-D| = |16+4-21|=1 となります。
|x^2+y^2-D|=0 を満たすような非負整数 x,y は存在しないので、答えは 1 です。
入力例 2
998244353
出力例 2
0
入力例 3
264428617
出力例 3
32
Score : 300 points
Problem Statement
You are given a positive integer D.
Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.
Constraints
- 1\leq D \leq 2\times 10^{12}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
D
Output
Print the answer.
Sample Input 1
21
Sample Output 1
1
For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.
There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.
Sample Input 2
998244353
Sample Output 2
0
Sample Input 3
264428617
Sample Output 3
32
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数の多重集合 S があります。はじめ S は空です。
Q 個のクエリが与えられるので順に処理してください。 クエリは次の 3 種類のいずれかです。
-
1 x
: S に x を 1 個追加する。 -
2 x c
: S から x を \mathrm{min}(c, (S に含まれる x の個数 )) 個削除する。 -
3
: (S の最大値 )- (S の最小値 ) を出力する。このクエリを処理するとき、 S が空でないことが保証される。
制約
- 1 \leq Q \leq 2\times 10^5
- 0 \leq x \leq 10^9
- 1 \leq c \leq Q
3
のクエリを処理するとき、S は空でない。- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q \mathrm{query}_1 \vdots \mathrm{query}_Q
i 番目のクエリを表す \mathrm{query}_i は以下の 3 種類のいずれかである。
1 x
2 x c
3
出力
3
のクエリに対する答えを順に改行区切りで出力せよ。
入力例 1
8 1 3 1 2 3 1 2 1 7 3 2 2 3 3
出力例 1
1 5 4
多重集合 S は以下のように変化します。
- 1 番目のクエリ : S に 3 を追加する。S は \lbrace3 \rbrace となる。
- 2 番目のクエリ : S に 2 を追加する。S は \lbrace2, 3\rbrace となる。
- 3 番目のクエリ : S = \lbrace 2, 3\rbrace の最大値は 3 、最小値は 2 なので、 3-2=1 を出力する。
- 4 番目のクエリ : S に 2 を追加する。S は \lbrace2,2,3 \rbrace となる。
- 5 番目のクエリ : S に 7 を追加する。S は \lbrace2, 2,3, 7\rbrace となる。
- 6 番目のクエリ : S = \lbrace2,2,3, 7\rbrace の最大値は 7 、最小値は 2 なので、 7-2=5 を出力する。
- 7 番目のクエリ : S に含まれる 2 の個数は 2 個なので、 \mathrm{min(2,3)} = 2 個の 2 を S から削除する。S は \lbrace3, 7\rbrace となる。
- 8 番目のクエリ : S = \lbrace3, 7\rbrace の最大値は 7 、最小値は 3 なので、 7-3=4 を出力する。
入力例 2
4 1 10000 1 1000 2 100 3 1 10
出力例 2
クエリ 3 が含まれない場合、何も出力してはいけません。
Score : 300 points
Problem Statement
We have a multiset of integers S, which is initially empty.
Given Q queries, process them in order. Each query is of one of the following types.
-
1 x
: Insert an x into S. -
2 x c
: Remove an x from S m times, where m = \mathrm{min}(c,( the number of x's contained in S)). -
3
: Print ( maximum value of S)-( minimum value of S). It is guaranteed that S is not empty when this query is given.
Constraints
- 1 \leq Q \leq 2\times 10^5
- 0 \leq x \leq 10^9
- 1 \leq c \leq Q
- When a query of type
3
is given, S is not empty. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q \mathrm{query}_1 \vdots \mathrm{query}_Q
\mathrm{query}_i, which denotes the i-th query, is in one of the following formats:
1 x
2 x c
3
Output
Print the answers for the queries of type 3
in the given order, separated by newlines.
Sample Input 1
8 1 3 1 2 3 1 2 1 7 3 2 2 3 3
Sample Output 1
1 5 4
The multiset S transitions as follows.
- 1-st query: insert 3 into S. S is now \lbrace 3 \rbrace.
- 2-nd query: insert 2 into S. S is now \lbrace 2, 3 \rbrace.
- 3-rd query: the maximum value of S = \lbrace 2, 3\rbrace is 3 and its minimum value is 2, so print 3-2=1.
- 4-th query: insert 2 into S. S is now \lbrace 2,2,3 \rbrace.
- 5-th query: insert 7 into S. S is now \lbrace 2, 2,3, 7\rbrace.
- 6-th query: the maximum value of S = \lbrace 2,2,3, 7\rbrace is 7 and its minimum value is 2, so print 7-2=5.
- 7-th query: since there are two 2's in S and \mathrm{min(2,3)} = 2, remove 2 from S twice. S is now \lbrace 3, 7\rbrace.
- 8-th query: the maximum value of S = \lbrace 3, 7\rbrace is 7 and its minimum value is 3, so print 7-3=4.
Sample Input 2
4 1 10000 1 1000 2 100 3 1 10
Sample Output 2
If the given queries do not contain that of type 3, nothing should be printed.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
正整数 N が与えられます。N は、2 つの相異なる素数 p,q を用いて N=p^2q と表せることがわかっています。
p,q を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 入力は全て整数
- 1\leq T\leq 10
- 1\leq N \leq 9\times 10^{18}
- N は、2 つの相異なる素数 p,q を用いて N=p^2q と表せる
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
各テストケースは以下の形式で与えられる。
N
出力
T 行出力せよ。
i\ (1\leq i \leq T) 行目には、i 番目のテストケースにおける p,q を空白区切りで出力せよ。 なお、この問題の制約下では、N=p^2q を満たす素数 p,q の組は 1 通りしか存在しないことが証明できる。
入力例 1
3 2023 63 1059872604593911
出力例 1
17 7 3 7 104149 97711
1 番目のテストケースについて、N=2023=17^2\times 7 です。よって、p=17,q=7 です。
Score : 400 points
Problem Statement
You are given a positive integer N. It is known that N can be represented as N=p^2q using two different prime numbers p and q.
Find p and q.
You have T test cases to solve.
Constraints
- All values in the input are integers.
- 1\leq T\leq 10
- 1\leq N \leq 9\times 10^{18}
- N can be represented as N=p^2q using two different prime numbers p and q.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
Each test case is in the following format:
N
Output
Print T lines.
The i-th (1\leq i \leq T) line should contain p and q for the i-th test case, separated by a space. Under the constraints of this problem, it can be proved that the pair of prime numbers p and q such that N=p^2q is unique.
Sample Input 1
3 2023 63 1059872604593911
Sample Output 1
17 7 3 7 104149 97711
For the first test case, we have N=2023=17^2\times 7. Thus, p=17 and q=7.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
H 行 W 列の格子状の区画に区切られた街があります。上から i 行目、左から j 列目の区画は、S_{i,j} が .
のとき道、#
のとき塀です。
高橋君は自分の家から魚屋に買い物に行くことにしました。高橋君の家は街の左上隅の区画にあり、魚屋は街の右下隅の区画にあります。
高橋君は、自分がいる区画から上下左右に隣接する道の区画に移動することができます。街の外に出ることはできません。
塀の区画に移動することはできませんが、高橋君は非常に腕力が強いため、パンチを 1 回繰り出すことで任意の 2\times 2 の区画内の塀を壊して道にすることができます。
高橋君が魚屋にたどり着くためには、最低何回パンチを繰り出せばよいか求めてください。
制約
- 2 \leq H,W \leq 500
- H,W は整数
- S_{i,j} は
.
または#
- S_{1,1} と S_{H,W} は
.
入力
入力は以下の形式で標準入力から与えられる。
H W S_{1,1} \ldots S_{1,W} \vdots S_{H,1} \ldots S_{H,W}
出力
答えを出力せよ。
入力例 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
出力例 1
1
例えば、以下の *
で表す 2\times 2 の区画にある塀を破壊すると魚屋にたどり着くことができます。
..#.. #.**# ##**# #.#.# ..#..
破壊対象の 2 \times 2 の区画の全てが塀である必要はありません。
入力例 2
5 7 ....... ######. ....... .###### .......
出力例 2
0
遠回りが必要ですが、塀を破壊することなく魚屋にたどり着くことができます。
入力例 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
出力例 3
5
Score : 500 points
Problem Statement
There is a town divided into a grid of cells with H rows and W columns. The cell at the i-th row from the top and j-th column from the left is a passable space if S_{i,j} is .
and a block if S_{i,j} is #
.
Takahashi will go from his house to a fish market. His house is in the cell at the top-left corner, and the fish market is in the cell at the bottom-right corner.
Takahashi can move one cell up, down, left, or right to a passable cell. He cannot leave the town. He cannot enter a block, either. However, his physical strength allows him to destroy all blocks in a square region with 2\times 2 cells of his choice with one punch, making these cells passable.
Find the minimum number of punches needed for Takahashi to reach the fish market.
Constraints
- 2 \leq H,W \leq 500
- H and W are integers.
- S_{i,j} is
.
or#
. - S_{1,1} and S_{H,W} are
.
.
Input
Input is given from Standard Input in the following format:
H W S_{1,1} \ldots S_{1,W} \vdots S_{H,1} \ldots S_{H,W}
Output
Print the answer.
Sample Input 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
Sample Output 1
1
He can reach the fish market by, for example, destroying the blocks in the square region with 2\times 2 cells marked *
below.
..#.. #.**# ##**# #.#.# ..#..
It is not required that all of the 2\times 2 cells in the region to punch are blocks.
Sample Input 2
5 7 ....... ######. ....... .###### .......
Sample Output 2
0
He can reach the fish market without destroying blocks, though he has to go a long way around.
Sample Input 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
M 個の数字 C_i が与えられます。
1 以上 N 以下の整数のうち、先頭に余分な 0 をつけずに 10 進法で表した時に C_1,\ldots,C_M を全て含むようなもの全ての和を、 998244353 で割った余りを求めてください。
制約
- 1 \leq N < 10^{10^4}
- 1 \leq M \leq 10
- 0 \leq C_1 < \ldots < C_M \leq 9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M C_1 \ldots C_M
出力
答えを出力せよ。
入力例 1
104 2 0 1
出力例 1
520
1 以上 104 以下の整数のうち、10 進法で表した時に 0
, 1
を共に含むようなものは、10,100,101,102,103,104 の 6 個あります。
これらの和は 520 です。
入力例 2
999 4 1 2 3 4
出力例 2
0
1 以上 999 以下の整数で、1
, 2
, 3
, 4
を全て含むようなものは存在しません。
入力例 3
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 5 0 2 4 6 8
出力例 3
397365274
998244353 で割った余りを求めてください。
Score : 500 points
Problem Statement
Given are M digits C_i.
Find the sum, modulo 998244353, of all integers between 1 and N (inclusive) that contain all of C_1, \ldots, C_M when written in base 10 without unnecessary leading zeros.
Constraints
- 1 \leq N < 10^{10^4}
- 1 \leq M \leq 10
- 0 \leq C_1 < \ldots < C_M \leq 9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M C_1 \ldots C_M
Output
Print the answer.
Sample Input 1
104 2 0 1
Sample Output 1
520
Between 1 and 104, there are six integers that contain both 0
and 1
when written in base 10: 10,100,101,102,103,104.
The sum of them is 520.
Sample Input 2
999 4 1 2 3 4
Sample Output 2
0
Between 1 and 999, no integer contains all of 1
, 2
, 3
, 4
.
Sample Input 3
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 5 0 2 4 6 8
Sample Output 3
397365274
Be sure to find the sum modulo 998244353.