実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
英小文字からなる文字列 S が与えられます。ここで S の長さは 3 以上 100 以下です。
S はある 1 文字を除いて全て同じ文字で構成されています。
他のどの文字とも異なる文字は前から何文字目でしょうか。
制約
- S は 2 種類の英小文字からなる長さ 3 以上 100 以下の文字列
- S はある 1 文字を除いて全て同じ文字
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
yay
出力例 1
2
yay の 2 文字目は、1 文字目とも 3 文字目とも異なります。
入力例 2
egg
出力例 2
1
入力例 3
zzzzzwz
出力例 3
6
Score: 150 points
Problem Statement
You are given a string S consisting of lowercase English letters. The length of S is between 3 and 100, inclusive.
All characters but one of S are the same.
Find x such that the x-th character of S differs from all other characters.
Constraints
- S is a string of length between 3 and 100, inclusive, consisting of two different lowercase English letters.
- All characters but one of S are the same.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
yay
Sample Output 1
2
The second character of yay differs from the first and third characters.
Sample Input 2
egg
Sample Output 2
1
Sample Input 3
zzzzzwz
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
A, B, C からなる長さ N の文字列 S が与えられます。
S の中で ABC が(連続な)部分文字列として初めて現れる位置を答えてください。すなわち、以下の条件を全て満たす整数 n のうち最小のものを答えてください。
- 1 \leq n \leq N - 2
- S の n 文字目から n+2 文字目までを取り出して出来る文字列は
ABCである。
ただし、ABC が S に現れない場合は -1 を出力してください。
制約
- 3 \leq N \leq 100
- S は
A,B,Cからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で ABC が部分文字列として初めて現れる位置を出力せよ。ただし、ABC が S に現れない場合は -1 を出力せよ。
入力例 1
8 ABABCABC
出力例 1
3
S の中で ABC が初めて現れるのは 3 文字目から 5 文字目までの位置です。よって 3 が答えになります。
入力例 2
3 ACB
出力例 2
-1
ABC が S に現れない場合は -1 を出力してください。
入力例 3
20 BBAAABBACAACABCBABAB
出力例 3
13
Score : 100 points
Problem Statement
You are given a string S of length N consisting of A, B, and C.
Find the position where ABC first appears as a (contiguous) substring in S. In other words, find the smallest integer n that satisfies all of the following conditions.
- 1 \leq n \leq N - 2.
- The string obtained by extracting the n-th through (n+2)-th characters of S is
ABC.
If ABC does not appear in S, print -1.
Constraints
- 3 \leq N \leq 100
- S is a string of length N consisting of
A,B, andC.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the position where ABC first appears as a substring in S, or -1 if it does not appear in S.
Sample Input 1
8 ABABCABC
Sample Output 1
3
ABC first appears in S at the 3-rd through 5-th characters of S. Therefore, the answer is 3.
Sample Input 2
3 ACB
Sample Output 2
-1
If ABC does not appear in S, print -1.
Sample Input 3
20 BBAAABBACAACABCBABAB
Sample Output 3
13
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
英小文字と ? からなる文字列 T と、英小文字のみからなる文字列 U が与えられます。
T は、英小文字のみからなる文字列 S のちょうど 4 文字を ? で置き換えることで得られた文字列です。
S が U を連続部分文字列として含んでいた可能性があるかどうか判定してください。
制約
- T は長さ 4 以上 10 以下の英小文字と
?からなる文字列 - T にはちょうど 4 つの
?が含まれる - U は長さ 1 以上 |T| 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
T U
出力
S が U を部分文字列として含んでいた可能性があるならば Yes を、そうでないならば No を出力せよ。
入力例 1
tak??a?h? nashi
出力例 1
Yes
例えば、S が takanashi である場合、これは nashi を連続部分文字列として含みます。
入力例 2
??e??e snuke
出力例 2
No
? がどのような文字であっても、S は snuke を連続部分文字列として含むことがありません。
入力例 3
???? aoki
出力例 3
Yes
Score : 250 points
Problem Statement
You are given a string T consisting of lowercase English letters and ?, and a string U consisting of lowercase English letters.
The string T is obtained by taking some lowercase-only string S and replacing exactly four of its characters with ?.
Determine whether it is possible that the original string S contained U as a contiguous substring.
Constraints
- T is a string of length between 4 and 10, inclusive, consisting of lowercase letters and
?. - T contains exactly four occurrences of
?. - U is a string of length between 1 and |T|, inclusive, consisting of lowercase letters.
Input
The input is given from Standard Input in the following format:
T U
Output
Print Yes if it is possible that the original string S contained U as a contiguous substring; otherwise, print No.
Sample Input 1
tak??a?h? nashi
Sample Output 1
Yes
For example, if S is takanashi, it contains nashi as a contiguous substring.
Sample Input 2
??e??e snuke
Sample Output 2
No
No matter what characters replace the ?s in T, S cannot contain snuke as a contiguous substring.
Sample Input 3
???? aoki
Sample Output 3
Yes
実行時間制限: 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
配点 : 300 点
問題文
xy 座標平面上の 2 つの格子点 (x_1, y_1), (x_2, y_2) からの距離がともに \sqrt{5} である格子点は存在しますか?
注記
xy 座標平面上にある点のうち、x 座標と y 座標がともに整数である点を格子点と呼びます。
また、xy 平面上の 2 点 (a, b), (c, d) の距離をユークリッド距離 \sqrt{(a - c)^2 + (b-d)^2} として定義します。
参考として、xy 平面の (0, 0) の上に黒丸を、(0, 0) からの距離が \sqrt{5} となる格子点の上に白丸を書いた図は以下のようになります。(x,y いずれかが整数となる部分に目盛り線を引いています。)

制約
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
x_1 y_1 x_2 y_2
出力
条件を満たす格子点が存在する場合は Yes を、存在しない場合は No を出力せよ。
入力例 1
0 0 3 3
出力例 1
Yes
- 点 (2,1) と (x_1, y_1) の距離は \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5}
- 点 (2,1) と (x_2, y_2) の距離は \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5}
- 点 (2, 1) は格子点
なので点 (2, 1) は条件を満たします。よって Yes を出力します。
なお、点 (1, 2) も条件を満たすことが同様にして確認できます。
入力例 2
0 1 2 3
出力例 2
No
条件を満たす格子点は存在しません。よって No を出力します。
入力例 3
1000000000 1000000000 999999999 999999999
出力例 3
Yes
点 (10^9 + 1, 10^9 - 2) および点 (10^9 - 2, 10^9 + 1)が条件を満たします。
Score : 300 points
Problem Statement
On an xy-coordinate plane, is there a lattice point whose distances from two lattice points (x_1, y_1) and (x_2, y_2) are both \sqrt{5}?
Notes
A point on an xy-coordinate plane whose x and y coordinates are both integers is called a lattice point.
The distance between two points (a, b) and (c, d) is defined to be the Euclidean distance between them, \sqrt{(a - c)^2 + (b-d)^2}.
The following figure illustrates an xy-plane with a black circle at (0, 0) and white circles at the lattice points whose distances from (0, 0) are \sqrt{5}. (The grid shows where either x or y is an integer.)

Constraints
- -10^9 \leq x_1 \leq 10^9
- -10^9 \leq y_1 \leq 10^9
- -10^9 \leq x_2 \leq 10^9
- -10^9 \leq y_2 \leq 10^9
- (x_1, y_1) \neq (x_2, y_2)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
x_1 y_1 x_2 y_2
Output
If there is a lattice point satisfying the condition, print Yes; otherwise, print No.
Sample Input 1
0 0 3 3
Sample Output 1
Yes
- The distance between points (2,1) and (x_1, y_1) is \sqrt{(0-2)^2 + (0-1)^2} = \sqrt{5};
- the distance between points (2,1) and (x_2, y_2) is \sqrt{(3-2)^2 + (3-1)^2} = \sqrt{5};
- point (2, 1) is a lattice point,
so point (2, 1) satisfies the condition. Thus, Yes should be printed.
One can also assert in the same way that (1, 2) also satisfies the condition.
Sample Input 2
0 1 2 3
Sample Output 2
No
No lattice point satisfies the condition, so No should be printed.
Sample Input 3
1000000000 1000000000 999999999 999999999
Sample Output 3
Yes
Point (10^9 + 1, 10^9 - 2) and point (10^9 - 2, 10^9 + 1) satisfy the condition.