Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 文字目が数字、2 文字目が文字 x、3 文字目が数字であるような 3 文字の文字列 S が与えられます。
S の 2 つの数の積を求めてください。
制約
- S は 1 文字目が 1 以上 9 以下の整数、2 文字目が文字
x、3 文字目が 1 以上 9 以下の整数であるような 3 文字の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
3x8
出力例 1
24
3 \times 8 = 24 より、24 を出力します。
入力例 2
9x9
出力例 2
81
9 \times 9 = 81 より、81 を出力します。
Score : 100 points
Problem Statement
You are given a 3-character string S, where the first character is a digit, the second character is the character x, and the third character is a digit.
Find the product of the two numbers in S.
Constraints
- S is a 3-character string where the first character is an integer between 1 and 9, inclusive, the second character is the character
x, and the third character is an integer between 1 and 9, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
3x8
Sample Output 1
24
From 3 \times 8 = 24, print 24.
Sample Input 2
9x9
Sample Output 2
81
From 9 \times 9 = 81, print 81.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 A, B が与えられます。 A^B の値を出力してください。
制約
- 1 \leq A, B \leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
4 3
出力例 1
64
4^3 = 64 であるので、64 を出力します。
入力例 2
5 5
出力例 2
3125
入力例 3
8 1
出力例 3
8
Score : 100 points
Problem Statement
Given integers A and B, print the value A^B.
Constraints
- 1 \leq A, B \leq 9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
4 3
Sample Output 1
64
4^3 = 64, so 64 should be printed.
Sample Input 2
5 5
Sample Output 2
3125
Sample Input 3
8 1
Sample Output 3
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋くんは、現在 N 枚のカードを持っています。 i 番目 (1\le i\le N) のカードには整数 A _ i が書かれています。
高橋くんは、以下の操作を可能な限り繰り返します。
- 同じ整数が書かれている異なる 2 枚のカードを選び、それら 2 枚のカードを食べる。食べたカードは永久に取り除かれ、以降の操作で選ぶことはできない。
操作ができなくなったときに残っているカードに書かれている整数の合計を求めてください。
制約
- 1\le N\le100
- 1\le A _ i\le100\ (1\le i\le N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \cdots A _ N
出力
残ったカードに書かれている整数の合計を出力せよ。
入力例 1
8 2 7 1 8 2 8 1 8
出力例 1
15
例えば、高橋くんは以下のように操作を行います。
- 4 枚目のカードと 6 枚目のカードにはどちらも 8 が書かれているため、それらを選び、食べる。
- 1 枚目のカードと 5 枚目のカードにはどちらも 2 が書かれているため、それらを選び、食べる。
- 3 枚目のカードと 7 枚目のカードにはどちらも 1 が書かれているため、それらを選び、食べる。

よって、残ったカードに書かれている整数の合計は 7+8=15 です。
8 と書かれたカードは 3 枚あるので、これらのうちの 2 枚を食べると残った 1 枚は食べられないことに注意してください。
入力例 2
5 1 2 3 4 5
出力例 2
15
高橋くんが操作を一度も行えない場合もあります。
入力例 3
15 58 97 74 16 97 74 97 16 51 52 58 52 74 32 43
出力例 3
297
Score : 200 points
Problem Statement
Takahashi currently has N cards. The i-th (1\le i\le N) card has the integer A _ i written on it.
He repeats the following operation as many times as possible.
- Choose two different cards with the same integer written on them, and eat those two cards. The eaten cards are permanently removed and cannot be chosen in subsequent operations.
Find the sum of the integers written on the cards that remain when the operation can no longer be performed.
Constraints
- 1\le N\le100
- 1\le A _ i\le100\ (1\le i\le N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \cdots A _ N
Output
Output the sum of the integers written on the remaining cards.
Sample Input 1
8 2 7 1 8 2 8 1 8
Sample Output 1
15
For example, Takahashi operates as follows.
- The fourth card and sixth card both have 8 written on them, so he chooses them and eats them.
- The first card and fifth card both have 2 written on them, so he chooses them and eats them.
- The third card and seventh card both have 1 written on them, so he chooses them and eats them.

Thus, the sum of the integers written on the remaining cards is 7+8=15.
Note that there are three cards with 8 written on them, so once two of them are eaten, the remaining one cannot be eaten.
Sample Input 2
5 1 2 3 4 5
Sample Output 2
15
It is possible that Takahashi cannot perform the operation even once.
Sample Input 3
15 58 97 74 16 97 74 97 16 51 52 58 52 74 32 43
Sample Output 3
297
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
以下の図で表される正五角形 P があります。

P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しいか判定してください。
制約
- S_1,S_2,T_1,T_2 は
A,B,C,D,Eのいずれかの文字 - S_1 \neq S_2
- T_1 \neq T_2
入力
入力は以下の形式で標準入力から与えられる。
S_1S_2 T_1T_2
出力
P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しい場合 Yes を、等しくない場合 No を出力せよ。
入力例 1
AC EC
出力例 1
Yes
P の点 A と点 C を結ぶ線分と、P の点 E と点 C を結ぶ線分の長さは等しいです。
入力例 2
DA EA
出力例 2
No
P の点 D と点 A を結ぶ線分と、P の点 E と点 A を結ぶ線分の長さは等しくありません。
入力例 3
BD BD
出力例 3
Yes
Score : 200 points
Problem Statement
A regular pentagon P is shown in the figure below.

Determine whether the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2.
Constraints
- Each of S_1, S_2, T_1, and T_2 is one of the characters
A,B,C,D, andE. - S_1 \neq S_2
- T_1 \neq T_2
Input
The input is given from Standard Input in the following format:
S_1S_2 T_1T_2
Output
If the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2, print Yes; otherwise, print No.
Sample Input 1
AC EC
Sample Output 1
Yes
The length of the line segment connecting point A and point C of P equals the length of the line segment connecting point E and point C.
Sample Input 2
DA EA
Sample Output 2
No
The length of the line segment connecting point D and point A of P does not equal the length of the line segment connecting point E and point A.
Sample Input 3
BD BD
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 国には「トラック運転手は A 分以上運転する際には B 分以上の休憩を取らなければならない」というルールがあります。
a, b からなる長さ N の文字列 S と正整数 A,B が与えられます。以下の条件を全て満たす整数組 (l,r) の個数を求めてください。
- 1\leq l \leq r \leq N
- S の l 文字目から r 文字目までに含まれる
aの個数が A 以上 - S の l 文字目から r 文字目までに含まれる
bの個数が B 未満
制約
- 1\leq N \leq 3\times 10^5
- 1 \leq A,B \leq N
- S は
a,bのみからなる長さ N の文字列 - 与えられる数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A B S
出力
答えを出力せよ。
入力例 1
11 4 2 abbaaabaaba
出力例 1
3
条件を満たす (l,r) の組は (4,8),(4,9),(5,9) の 3 個です。
入力例 2
13 1 2 bbbbbbbbbbbbb
出力例 2
0
条件を満たす (l,r) の組は存在しません。
Score : 300 points
Problem Statement
In AtCoder Country, there is a rule that "a truck driver must take a break of at least B minutes when driving for A minutes or more."
You are given a string S of length N consisting of a and b, and positive integers A and B. Find the number of integer pairs (l,r) that satisfy all of the following conditions.
- 1\leq l \leq r \leq N
- The number of
ain the substring from the l-th character through the r-th character of S is greater than or equal to A. - The number of
bin the substring from the l-th character through the r-th character of S is less than B.
Constraints
- 1\leq N \leq 3\times 10^5
- 1 \leq A,B \leq N
- S is a string of length N consisting of
aandb. - All input numbers are integers.
Input
The input is given from Standard Input in the following format:
N A B S
Output
Print the answer.
Sample Input 1
11 4 2 abbaaabaaba
Sample Output 1
3
The pairs (l,r) that satisfy the conditions are (4,8),(4,9),(5,9), which is three pairs.
Sample Input 2
13 1 2 bbbbbbbbbbbbb
Sample Output 2
0
There are no pairs (l,r) that satisfy the conditions.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
縦 H マス、横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスを (i,j) と表します。
(i,j) には文字 G_{i,j} が書きこまれています。ここで G_{i,j} は U, D, L, R のいずれかです。
あなたは (1,1) にいます。あなたは移動することができなくなるまで次の操作を繰り返します。
あなたは現在 (i,j) にいるとする。
G_{i,j} がUであり、かつ i \neq 1 ならば (i-1,j) へ移動する。
G_{i,j} がDであり、かつ i \neq H ならば (i+1,j) へ移動する。
G_{i,j} がLであり、かつ j \neq 1 ならば (i,j-1) へ移動する。
G_{i,j} がRであり、かつ j \neq W ならば (i,j+1) へ移動する。
それ以外の場合、あなたは移動することができない。
操作を終了した時点であなたがいるマスを出力してください。
ただし、あなたが操作を終了することなく無限に移動し続ける場合は -1 を出力してください。
制約
- 1 \leq H, W \leq 500
- G_{i,j} は
U,D,L,Rのいずれかである。 - H, W は整数である。
入力
入力は以下の形式で標準入力から与えられる。
H W
G_{1,1}G_{1,2}\dots G_{1,W}
G_{2,1}G_{2,2}\dots G_{2,W}
\vdots
G_{H,1}G_{H,2}\dots G_{H,W}
出力
操作を終了した時点であなたが (i,j) にいる場合は次の形式で出力せよ。
i j
また、無限に動き続ける場合は -1 を出力せよ。
入力例 1
2 3 RDU LRU
出力例 1
1 3
あなたは (1, 1) \to (1, 2) \to (2, 2) \to (2, 3) \to (1, 3) の順に動いたあとに操作を終了します。よって答えは (1, 3) です。
入力例 2
2 3 RRD ULL
出力例 2
-1
あなたは (1, 1) \to (1, 2) \to (1, 3) \to (2, 3) \to (2, 2) \to (2, 1) \to (1, 1) \to (1, 2) \to \dots というように無限に動き続けます。この場合は -1 を出力します。
入力例 3
9 44 RRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR RRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD DRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR DDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD RDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR RDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR RDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR RDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR RRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR
出力例 3
9 5
Score : 300 points
Problem Statement
We have a grid with H horizontal rows and W vertical columns. (i, j) denotes the square at the i-th row from the top and j-th column from the left.
(i,j) has a character G_{i,j} written on it. G_{i,j} is U, D, L, or R.
You are initially at (1,1). You repeat the following operation until you cannot make a move.
Let (i,j) be the square you are currently at.
If G_{i,j} isUand i \neq 1, move to (i-1,j).
If G_{i,j} isDand i \neq H, move to (i+1,j).
If G_{i,j} isLand j \neq 1, move to (i,j-1).
If G_{i,j} isRand j \neq W, move to (i,j+1).
Otherwise, you cannot make a move.
Print the square you end up at when you cannot make a move.
If you indefinitely repeat moving, print -1 instead.
Constraints
- 1 \leq H, W \leq 500
- G_{i,j} is
U,D,L, orR. - H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
G_{1,1}G_{1,2}\dots G_{1,W}
G_{2,1}G_{2,2}\dots G_{2,W}
\vdots
G_{H,1}G_{H,2}\dots G_{H,W}
Output
If you end up at (i, j), print it in the following format:
i j
If you indefinitely repeat moving, print -1.
Sample Input 1
2 3 RDU LRU
Sample Output 1
1 3
You will move as (1, 1) \to (1, 2) \to (2, 2) \to (2, 3) \to (1, 3), ending up here, so the answer is (1, 3).
Sample Input 2
2 3 RRD ULL
Sample Output 2
-1
You will indefinitely repeat moving as (1, 1) \to (1, 2) \to (1, 3) \to (2, 3) \to (2, 2) \to (2, 1) \to (1, 1) \to (1, 2) \to \dots, so -1 should be printed in this case.
Sample Input 3
9 44 RRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR RRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD DRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR DDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD RDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR RDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR RDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR RDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR RRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR
Sample Output 3
9 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
H 行 W 列のマス目があります。上から i 行目 (1\leq i\leq H)、左から j 列目 (1\leq j\leq W) のマスをマス (i,j) と呼ぶことにします。
はじめ、マス (i,j) は S_{i,j} が # のとき黒、. のとき白で塗られています。
以下の操作を 10^{100} 回行います。
- 白で塗られているマスであって、そのマスに辺で隣接するマスのうちちょうど 1 つが黒で塗られているようなマスの集合を T とする。T の各マスに対して、そのマスを黒で塗る。ただし、2 つのマス (i_1,j_1),(i_2,j_2) が辺で隣接するとは、 |i_1-i_2|+|j_1-j_2|=1 であることをいう。
すべての操作が終わったあとに黒く塗られているマスの個数を求めてください。
制約
- 2\leq H,W
- HW\leq 3\times 10^5
- H,W は整数
- S_{i,j} は
#または.
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1}S_{1,2}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}
出力
答えを出力せよ。
入力例 1
9 9 ......... ......... ......... ......... ....#.... ......... ......... ......... .........
出力例 1
57
操作によってマス目は以下のように変化します。(上の数字は操作回数を表しており、10 回目の操作後まで表示しています。)

最終的に黒く塗られたマスは 57 個です。
入力例 2
2 2 .. ..
出力例 2
0
入力例 3
10 10 .......... ....#..... #.......#. ......#... .......#.. .....#.... .......... .......... ..#...#... .......#..
出力例 3
64
Score : 425 points
Problem Statement
There is a grid with H rows and W columns. We call the cell at the i-th row from the top (1\leq i\leq H) and j-th column from the left (1\leq j\leq W) as cell (i,j).
Initially, cell (i,j) is colored black if S_{i,j} is # and white if it is ..
Perform the following operation 10^{100} times:
- Let T be the set of cells that are colored white and have exactly one adjacent cell colored black. Color each cell in T black. Here, two cells (i_1,j_1) and (i_2,j_2) are adjacent if and only if |i_1-i_2|+|j_1-j_2|=1.
Find the number of cells that are colored black after all operations are completed.
Constraints
- 2\leq H,W
- HW\leq 3\times 10^5
- H and W are integers.
- S_{i,j} is
#or..
Input
The input is given from Standard Input in the following format:
H W
S_{1,1}S_{1,2}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}
Output
Output the answer.
Sample Input 1
9 9 ......... ......... ......... ......... ....#.... ......... ......... ......... .........
Sample Output 1
57
The grid changes as follows through the operations. (The number above represents the operation count. The first ten operations are displayed.)

Eventually, 57 cells are colored black.
Sample Input 2
2 2 .. ..
Sample Output 2
0
Sample Input 3
10 10 .......... ....#..... #.......#. ......#... .......#.. .....#.... .......... .......... ..#...#... .......#..
Sample Output 3
64
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
以下の条件を全て満たす正整数列 A=(A_1,\dots,A_{|A|}) を良い数列と定めます。
- |A|\geq 3
- A は等差数列である。即ち、全ての 1 \leq i \leq |A|-1 について A_{i+1}-A_{i}=A_2-A_1
- A_2-A_1 > 0
良い数列のうち、要素の総積が N 以下であるものの個数を求めてください。
なお、制約の条件下で答えが 10^{18} 以下となることが証明されます。
制約
- 1 \leq N \leq 10^{18}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
120
出力例 1
18
総積が 24 以下の良い数列は (1,2,3),(1,2,3,4),(1,3,5),(2,3,4) の 4 個です。
入力例 2
1000000000000000000
出力例 2
1051148114007
Score : 450 points
Problem Statement
A sequence of positive integers A=(A_1,\dots,A_{|A|}) is called a good sequence if it satisfies all of the following conditions.
- |A|\geq 3
- A is an arithmetic progression; that is, A_{i+1}-A_{i}=A_2-A_1 for all 1 \leq i \leq |A|-1.
- A_2-A_1 > 0
Find the number of good sequences such that the product of all elements is at most N.
It can be proved that the answer is at most 10^{18} under the constraints.
Constraints
- 1 \leq N \leq 10^{18}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
120
Sample Output 1
18
There are 4 good sequences whose product is at most 24: (1,2,3),(1,2,3,4),(1,3,5),(2,3,4).
Sample Input 2
1000000000000000000
Sample Output 2
1051148114007
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
1 から 2^N の番号がついた 2^N 人でじゃんけん大会を行います。
大会は以下の形式で行われます。
- 参加者を人 1、人 2、 \ldots、人 2^N の順に横一列に並べる。
- 現在の列の長さを 2M として、各 i\ (1\leq i \leq M) について左から 2i-1 番目の人と左から 2i 番目の人で試合を行い、負けた M 人を列から外す。これを N 回繰り返す。
ここで、人 i はちょうど j 回試合に勝つと C_{i,j} 円獲得できます。1 回も勝たなかった場合は何も貰えません。全ての試合の勝敗を自由に決められるとき、人 1、人 2、 \ldots、人 2^N が貰えるお金の合計の最大値を求めてください。
制約
- 1 \leq N \leq 16
- 1 \leq C_{i,j} \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
C_{1,1} C_{1,2} \ldots C_{1,N}
C_{2,1} C_{2,2} \ldots C_{2,N}
\vdots
C_{2^N,1} C_{2^N,2} \ldots C_{2^N,N}
出力
答えを出力せよ。
入力例 1
2 2 5 6 5 2 1 7 9
出力例 1
15
初めの列は (1,2,3,4) です。
人 1 と人 2 の試合で人 2 が勝ち、人 3 と人 4 の試合で人 4 が勝ったとすると、列は (2,4) になります。
次に人 2 と人 4 の試合で人 4 が勝ったとすると、列は (4) になり、これで大会が終了となります。
このとき、人 2 はちょうど 1 回勝ち、人 4 はちょうど 2 回勝ったので、貰えるお金の合計は 0+6+0+9=15 となります。 これが貰えるお金の合計の最大値です。
入力例 2
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
出力例 2
4
Score : 500 points
Problem Statement
2^N people, numbered 1 to 2^N, will participate in a rock-paper-scissors tournament.
The tournament proceeds as follows:
- The participants are arranged in a row in the order Person 1, Person 2, \ldots, Person 2^N from left to right.
- Let 2M be the current length of the row. For each i\ (1\leq i \leq M), the (2i-1)-th and (2i)-th persons from the left play a game against each other. Then, the M losers are removed from the row. This process is repeated N times.
Here, if Person i wins exactly j games, they receive C_{i,j} yen (Japanese currency). A person winning zero games receives nothing. Find the maximum possible total amount of money received by the 2^N people if the results of all games can be manipulated freely.
Constraints
- 1 \leq N \leq 16
- 1 \leq C_{i,j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
C_{1,1} C_{1,2} \ldots C_{1,N}
C_{2,1} C_{2,2} \ldots C_{2,N}
\vdots
C_{2^N,1} C_{2^N,2} \ldots C_{2^N,N}
Output
Print the answer.
Sample Input 1
2 2 5 6 5 2 1 7 9
Sample Output 1
15
The initial row of the people is (1,2,3,4).
If Person 2 wins the game against Person 1, and Person 4 wins the game against Person 3, the row becomes (2,4).
Then, if Person 4 wins the game against Person 2, the row becomes (4), and the tournament ends.
Here, Person 2 wins exactly 1 game, and Person 4 wins exactly 2 games, so they receive 0+6+0+9=15 yen in total, which is the maximum possible sum.
Sample Input 2
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output 2
4