実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
3 つの数字 x,y,z をこの順に並べてできる 3 桁の整数を xyz と表すことにします。
どの桁も 0 でない 3 桁の整数 abc が与えられるので、abc+bca+cab を求めてください。
制約
- abc は どの桁も 0 でない 3 桁の整数
入力
入力は以下の形式で標準入力から与えられる。
abc
出力
答えを出力せよ。
入力例 1
123
出力例 1
666
123+231+312=666 となります。
入力例 2
999
出力例 2
2997
999+999+999=2997 となります。
Score : 100 points
Problem Statement
Let xyz denote the 3-digit integer whose digits are x, y, z from left to right.
Given a 3-digit integer abc none of whose digits is 0, find abc+bca+cab.
Constraints
- abc is a 3-digit integer abc none of whose digits is 0.
Input
Input is given from Standard Input in the following format:
abc
Output
Print the answer.
Sample Input 1
123
Sample Output 1
666
We have 123+231+312=666.
Sample Input 2
999
Sample Output 2
2997
We have 999+999+999=2997.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
正整数 N が与えられるので、
N 個の 0
と N+1 個の 1
からなる、0
と 1
が交互に並んだ文字列を出力してください。
制約
- N は整数
- 1 \leq N \leq 100
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
4
出力例 1
101010101
4 個の 0
と 5 個の 1
からなる、0
と 1
が交互に並んだ文字列は 101010101
です。
入力例 2
1
出力例 2
101
入力例 3
10
出力例 3
101010101010101010101
Score: 100 points
Problem Statement
Given a positive integer N, print a string of N zeros and N+1 ones where 0
and 1
alternate.
Constraints
- N is an integer.
- 1 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
4
Sample Output 1
101010101
A string of four zeros and five ones where 0
and 1
alternate is 101010101
.
Sample Input 2
1
Sample Output 2
101
Sample Input 3
10
Sample Output 3
101010101010101010101
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
以下のような N 個の整数列 A_0,\ldots,A_{N-1} を求めてください。
- 各 i (0\leq i \leq N-1) について、A_i の長さは i+1 である。
-
各 i,j (0\leq i \leq N-1, 0 \leq j \leq i) について、A_i の j+1 番目の値 a_{i,j} は次のように定められる。
- j=0 または j=i の時、a_{i,j}=1
- それ以外の時、a_{i,j} = a_{i-1,j-1} + a_{i-1,j}
制約
- 1 \leq N \leq 30
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N 行出力せよ。 i 行目には A_{i-1} の値を順に空白区切りで出力せよ。
入力例 1
3
出力例 1
1 1 1 1 2 1
入力例 2
10
出力例 2
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
Score : 200 points
Problem Statement
Find the N integer sequences A_0,\ldots,A_{N-1} defined as follows.
- For each i (0\leq i \leq N-1), the length of A_i is i+1.
- For each i and j (0\leq i \leq N-1, 0 \leq j \leq i), the (j+1)-th term of A_i, denoted by a_{i,j}, is defined as follows.
- a_{i,j}=1, if j=0 or j=i.
- a_{i,j} = a_{i-1,j-1} + a_{i-1,j}, otherwise.
Constraints
- 1 \leq N \leq 30
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print N lines. The i-th line should contain the terms of A_{i-1} separated by spaces.
Sample Input 1
3
Sample Output 1
1 1 1 1 2 1
Sample Input 2
10
Sample Output 2
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
無限に長いピアノの鍵盤があります。 この鍵盤内の連続する区間であって、白鍵 W 個と黒鍵 B 個からなるものは存在しますか?
文字列 wbwbwwbwbwbw
を無限に繰り返してできる文字列を S とおきます。
S の部分文字列であって、W 個の w
と B 個の b
からなるものは存在しますか?
S の部分文字列とは
S の部分文字列とは、ある 2 つの正整数 l,r\ (l\leq r) に対して、S の l 文字目、l+1 文字目、\dots、r 文字目をこの順に繋げてできる文字列のことをいいます。制約
- W,B は整数
- 0\leq W,B \leq 100
- W+B \geq 1
入力
入力は以下の形式で標準入力から与えられる。
W B
出力
S の部分文字列であって、W 個の w
と B 個の b
からなるものが存在するならば Yes
を、存在しないならば No
を出力せよ。
入力例 1
3 2
出力例 1
Yes
S の最初の 15 文字は wbwbwwbwbwbwwbw
であり、S の 11 文字目から 15 文字目までを取り出してできる文字列 bwwbw
は 3 個の w
と 2 個の b
からなる部分文字列の一例です。
入力例 2
3 0
出力例 2
No
3 個の w
と 0 個の b
からなる文字列は www
のみですが、これは S の部分文字列ではありません。
入力例 3
92 66
出力例 3
Yes
Score: 200 points
Problem Statement
There is an infinitely long piano keyboard. Is there a continuous segment within this keyboard that consists of W white keys and B black keys?
Let S be the string formed by infinitely repeating the string wbwbwwbwbwbw
.
Is there a substring of S that consists of W occurrences of w
and B occurrences of b
?
What is a substring of S?
A substring of S is a string that can be formed by concatenating the l-th, (l+1)-th, \dots, r-th characters of S in this order for some two positive integers l and r (l\leq r).Constraints
- W and B are integers.
- 0\leq W,B \leq 100
- W+B \geq 1
Input
The input is given from Standard Input in the following format:
W B
Output
If there is a substring of S that consists of W occurrences of w
and B occurrences of b
, print Yes
; otherwise, print No
.
Sample Input 1
3 2
Sample Output 1
Yes
The first 15 characters of S are wbwbwwbwbwbwwbw
. You can take the 11-th through 15-th characters to form the string bwwbw
, which is a substring consisting of three occurrences of w
and two occurrences of b
.
Sample Input 2
3 0
Sample Output 2
No
The only string consisting of three occurrences of w
and zero occurrences of b
is www
, which is not a substring of S.
Sample Input 3
92 66
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
あなたはゲームをプレイしています。
N 人の敵が一列に並んでおり、前から i 番目の敵の体力は H_i です。
あなたは 0 で初期化された変数 T を使い、全ての敵の体力が 0 以下になるまで次の行動を繰り返します。
- T を 1 増やす。その後、体力が 1 以上である最も前の敵を攻撃する。このとき、T が 3 の倍数ならばその敵の体力は 3 減り、そうでないなら 1 減る。
全ての敵の体力が 0 以下になったときの T の値を求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq H_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N H_1 H_2 \ldots H_N
出力
答えを出力せよ。
入力例 1
3 6 2 2
出力例 1
8
行動は次のように行われます。
- T=1 になる。1 番目の敵を攻撃し、その敵の体力は 6-1=5 となる。
- T=2 になる。1 番目の敵を攻撃し、その敵の体力は 5-1=4 となる。
- T=3 になる。1 番目の敵を攻撃し、その敵の体力は 4-3=1 となる。
- T=4 になる。1 番目の敵を攻撃し、その敵の体力は 1-1=0 となる。
- T=5 になる。2 番目の敵を攻撃し、その敵の体力は 2-1=1 となる。
- T=6 になる。2 番目の敵を攻撃し、その敵の体力は 1-3=-2 となる。
- T=7 になる。3 番目の敵を攻撃し、その敵の体力は 2-1=1 となる。
- T=8 になる。3 番目の敵を攻撃し、その敵の体力は 1-1=0 となる。
入力例 2
9 1 12 123 1234 12345 123456 1234567 12345678 123456789
出力例 2
82304529
入力例 3
5 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
3000000000
オーバーフローに注意してください。
Score : 300 points
Problem Statement
You are playing a game.
There are N enemies lined up in a row, and the i-th enemy from the front has a health of H_i.
You will repeat the following action until the healths of all enemies become 0 or less, using a variable T initialized to 0.
- Increase T by 1. Then, attack the frontmost enemy with health 1 or more. If T is a multiple of 3, the enemy's health decreases by 3; otherwise, it decreases by 1.
Find the value of T when the healths of all enemies become 0 or less.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq H_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H_1 H_2 \ldots H_N
Output
Print the answer.
Sample Input 1
3 6 2 2
Sample Output 1
8
The actions are performed as follows:
- T becomes 1. Attack the 1st enemy, and its health becomes 6-1=5.
- T becomes 2. Attack the 1st enemy, and its health becomes 5-1=4.
- T becomes 3. Attack the 1st enemy, and its health becomes 4-3=1.
- T becomes 4. Attack the 1st enemy, and its health becomes 1-1=0.
- T becomes 5. Attack the 2nd enemy, and its health becomes 2-1=1.
- T becomes 6. Attack the 2nd enemy, and its health becomes 1-3=-2.
- T becomes 7. Attack the 3rd enemy, and its health becomes 2-1=1.
- T becomes 8. Attack the 3rd enemy, and its health becomes 1-1=0.
Sample Input 2
9 1 12 123 1234 12345 123456 1234567 12345678 123456789
Sample Output 2
82304529
Sample Input 3
5 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
3000000000
Beware of integer overflow.