実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
6 つの面を持つサイコロが 3 個あります。
どのサイコロも、面には 1,2,3,4,5,6 が書かれています。
これらのサイコロを同時に振ったとき、出た目の合計が X になることはありますか?
制約
- X は 1 以上 20 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
出た目の合計が X になることがあれば Yes 、なければ No を出力せよ。
入力例 1
15
出力例 1
Yes
例えば、出目が 4,5,6 のとき、合計は 15 となります。
入力例 2
2
出力例 2
No
Score : 100 points
Problem Statement
There are three dice, each with six faces.
Each die has 1,2,3,4,5,6 written on its faces.
When these dice are rolled simultaneously, is it possible for the sum of the rolled values to be X?
Constraints
- X is an integer between 1 and 20, inclusive.
Input
The input is given from Standard Input in the following format:
X
Output
If it is possible for the sum of the rolled values to be X, output Yes; otherwise, output No.
Sample Input 1
15
Sample Output 1
Yes
For example, if the rolled values are 4,5,6, the sum is 15.
Sample Input 2
2
Sample Output 2
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
文字列 S が与えられます。ここで、S の 1 文字目は英大文字、2 文字目以降は英小文字です。
S の 1 文字目と UPC をこの順に結合した文字列を出力してください。
制約
- S は長さ 1 以上 100 以下の文字列
- S の 1 文字目は英大文字
- S の 2 文字目以降は英小文字
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の 1 文字目と UPC をこの順に結合した文字列を出力せよ。
入力例 1
Kyoto
出力例 1
KUPC
Kyoto の 1 文字目は K であるため、K と UPC を結合した KUPC を出力します。
入力例 2
Tohoku
出力例 2
TUPC
Score : 100 points
Problem Statement
You are given a string S. Here, the first character of S is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Print the string formed by concatenating the first character of S and UPC in this order.
Constraints
- S is a string of length between 1 and 100, inclusive.
- The first character of S is an uppercase English letter.
- The second and subsequent characters of S are lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the string formed by concatenating the first character of S and UPC in this order.
Sample Input 1
Kyoto
Sample Output 1
KUPC
The first character of Kyoto is K, so concatenate K and UPC, and print KUPC.
Sample Input 2
Tohoku
Sample Output 2
TUPC
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
1,\ldots,N の番号のついた N 人の選手がゲームを行いました。選手 i のスコアは A_i であり、スコアが小さい方が上位になります。
ブービー賞に該当する選手、すなわち、下位から 2 番目の選手の番号を求めてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i は相異なる
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
6 1 123 12345 12 1234 123456
出力例 1
3
6 人中 5 位になるのは、選手 3 です。
入力例 2
5 3 1 4 15 9
出力例 2
5
Score : 200 points
Problem Statement
N players, who are numbered 1, \ldots, N, have played a game. Player i has scored A_i, and a player with a smaller score ranks higher.
The player who ranks the second lowest will receive a booby prize. Who is this player? Answer with an integer representing the player.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
6 1 123 12345 12 1234 123456
Sample Output 1
3
It is Player 3 who ranks fifth among the six players.
Sample Input 2
5 3 1 4 15 9
Sample Output 2
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。ここで、 A の各要素は -1 または 1 以上 N 以下の整数です。
以下の条件を全て満たす長さ N の整数列 P=(P_1,P_2,\ldots,P_N) が存在するか判定し、存在するならば一つ求めてください。
- P は (1,2,\ldots,N) を並び替えてできる整数列である。
- i=1,2,\ldots,N に対し、 A_i \neq -1 ならば P_i=A_i が成り立つ。
制約
- 1\le N\le 10
- A_i=-1 または 1\le A_i \le N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
条件を全て満たす P が存在しない場合は No と出力せよ。
そうでない場合、条件を全て満たす P を以下の形式で出力せよ。
Yes P_1 P_2 \ldots P_N
条件を全て満たす P が複数存在する場合、どれを出力しても正答となる。
入力例 1
4 -1 -1 2 -1
出力例 1
Yes 3 1 2 4
P=(3,1,2,4) とすると条件を全て満たします。
このほかにも、 P=(1,3,2,4) や P=(4,3,2,1) なども条件を全て満たします。
入力例 2
5 -1 -1 1 -1 1
出力例 2
No
条件を全て満たす P は存在しません。
入力例 3
7 3 -1 4 -1 5 -1 2
出力例 3
Yes 3 7 4 1 5 6 2
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N. Here, each element of A is either -1 or an integer between 1 and N, inclusive.
Determine whether there exists an integer sequence P=(P_1,P_2,\ldots,P_N) of length N that satisfies all of the following conditions, and if it exists, find one.
- P is a permutation of (1,2,\ldots,N).
- For i=1,2,\ldots,N, if A_i \neq -1, then P_i=A_i holds.
Constraints
- 1\le N\le 10
- A_i=-1 or 1\le A_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 \ldots A_N
Output
If there is no P that satisfies all conditions, output No.
Otherwise, output P that satisfies all conditions in the following format:
Yes P_1 P_2 \ldots P_N
If there are multiple P that satisfy all conditions, any of them may be output.
Sample Input 1
4 -1 -1 2 -1
Sample Output 1
Yes 3 1 2 4
P=(3,1,2,4) satisfies all conditions.
Besides this, P=(1,3,2,4) or P=(4,3,2,1) also satisfies all conditions.
Sample Input 2
5 -1 -1 1 -1 1
Sample Output 2
No
There is no P that satisfies all conditions.
Sample Input 3
7 3 -1 4 -1 5 -1 2
Sample Output 3
Yes 3 7 4 1 5 6 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 棟のビルが等間隔に一列に並んでいます。手前から i 番目のビルの高さは H_i です。
あなたは次の条件をともに満たすようにいくつかのビルを選んで電飾で飾ろうとしています。
- 選んだビルたちは高さが等しい
- 選んだビルたちは等間隔に並んでいる
最大でいくつのビルを選ぶことができますか? なお、ちょうど 1 つのビルを選んだときは条件を満たすとみなします。
制約
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N H_1 \ldots H_N
出力
答えを出力せよ。
入力例 1
8 5 7 5 7 7 5 7 7
出力例 1
3
手前から 2,5,8 番目のビルを選ぶと条件を満たします。
入力例 2
10 100 200 300 400 500 600 700 800 900 1000
出力例 2
1
1つのビルを選んだときは条件を満たすとみなします。
入力例 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
出力例 3
3
Score : 350 points
Problem Statement
There are N buildings arranged in a line at equal intervals. The height of the i-th building from the front is H_i.
You want to decorate some of these buildings with illuminations so that both of the following conditions are satisfied:
- The chosen buildings all have the same height.
- The chosen buildings are arranged at equal intervals.
What is the maximum number of buildings you can choose? If you choose exactly one building, it is considered to satisfy the conditions.
Constraints
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H_1 \ldots H_N
Output
Print the answer.
Sample Input 1
8 5 7 5 7 7 5 7 7
Sample Output 1
3
Choosing the 2nd, 5th, and 8th buildings from the front satisfies the conditions.
Sample Input 2
10 100 200 300 400 500 600 700 800 900 1000
Sample Output 2
1
Choosing just one building is considered to satisfy the conditions.
Sample Input 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
Sample Output 3
3