Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
二つの文字 x と y は以下の 3 つの条件のうちどれか 1 つを満たすとき、似た文字と呼ばれます。
- x と y は同じ文字
- x と y の片方が
1で、もう片方がl - x と y の片方が
0で、もう片方がo
また、長さ N の文字列 S と T は以下の条件を満たすとき、似た文字列と呼ばれます。
- 任意の i\ (1\leq i\leq N) について、 S の i 番目の文字と T の i 番目の文字は似た文字
英小文字及び数字からなる長さ N の文字列 S,T が与えられます。 S と T が似た文字列か判定してください。
制約
- N は 1 以上 100 以下の整数
- S,T は英小文字及び数字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S T
出力
S と T が似た文字列の場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
3 l0w 1ow
出力例 1
Yes
S の 1 文字目は lで、T の 1 文字目は 1です。これらは似た文字です。
S の 2 文字目は 0で、T の 2 文字目は oです。これらは似た文字です。
S の 3 文字目は wで、T の 3 文字目は wです。これらは似た文字です。
よって S と T は似た文字列です。
入力例 2
3 abc arc
出力例 2
No
S の 2 文字目は bで、T の 2 文字目は rです。これらは似た文字ではありません。
よって S と T は似た文字列ではありません。
入力例 3
4 nok0 n0ko
出力例 3
Yes
Score : 100 points
Problem Statement
Two characters x and y are called similar characters if and only if one of the following conditions is satisfied:
- x and y are the same character.
- One of x and y is
1and the other isl. - One of x and y is
0and the other iso.
Two strings S and T, each of length N, are called similar strings if and only if:
- for all i\ (1\leq i\leq N), the i-th character of S and the i-th character of T are similar characters.
Given two length-N strings S and T consisting of lowercase English letters and digits, determine if S and T are similar strings.
Constraints
- N is an integer between 1 and 100.
- Each of S and T is a string of length N consisting of lowercase English letters and digits.
Input
The input is given from Standard Input in the following format:
N S T
Output
Print Yes if S and T are similar strings, and No otherwise.
Sample Input 1
3 l0w 1ow
Sample Output 1
Yes
The 1-st character of S is l, and the 1-st character of T is 1. These are similar characters.
The 2-nd character of S is 0, and the 2-nd character of T is o. These are similar characters.
The 3-rd character of S is w, and the 3-rd character of T is w. These are similar characters.
Thus, S and T are similar strings.
Sample Input 2
3 abc arc
Sample Output 2
No
The 2-nd character of S is b, and the 2-nd character of T is r. These are not similar characters.
Thus, S and T are not similar strings.
Sample Input 3
4 nok0 n0ko
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数列 A=(A_1,A_2,A_3) が与えられます。
A の要素を自由に並べ替えた列を B=(B_1,B_2,B_3) とします。
このとき、 B_1 \times B_2 = B_3 を満たすようにできるか判定してください。
制約
- 入力は全て整数
- 1 \le A_1,A_2,A_3 \le 100
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3
出力
B_1 \times B_2 = B_3 を満たすようにできるなら Yes 、そうでないなら No と出力せよ。
入力例 1
3 15 5
出力例 1
Yes
A=(3,15,5) です。
B=(3,5,15) と並べ替えることで、 B_1 \times B_2 = B_3 を満たすようにできます。
入力例 2
5 3 2
出力例 2
No
B をどのように定めても、 B_1 \times B_2 = B_3 を満たすようにはできません。
入力例 3
3 3 9
出力例 3
Yes
Score : 100 points
Problem Statement
You are given a sequence of integers A = (A_1, A_2, A_3).
Let B = (B_1, B_2, B_3) be any permutation of A.
Determine whether it is possible that B_1 \times B_2 = B_3.
Constraints
- All input values are integers.
- 1 \le A_1, A_2, A_3 \le 100
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3
Output
If it is possible that B_1 \times B_2 = B_3, print Yes; otherwise, print No.
Sample Input 1
3 15 5
Sample Output 1
Yes
Here, A=(3,15,5). By rearranging it as B=(3,5,15), we can satisfy B_1 \times B_2 = B_3.
Sample Input 2
5 3 2
Sample Output 2
No
No permutation of B satisfies B_1 \times B_2 = B_3.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の文字列 S が与えられます。
S に連続して含まれる na を全て nya に置き換えて得られる文字列を答えてください。
制約
- N は 1 以上 1000 以下の整数
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
4 naan
出力例 1
nyaan
naan に連続して含まれる na を全て nya に置き換えて得られる文字列は nyaan です。
入力例 2
4 near
出力例 2
near
S に na が連続して含まれないこともあります。
入力例 3
8 national
出力例 3
nyationyal
Score : 200 points
Problem Statement
You are given a string S of length N.
Find the string obtained by replacing all contiguous occurrences of na in S with nya.
Constraints
- N is an integer between 1 and 1000, inclusive.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
4 naan
Sample Output 1
nyaan
Replacing all contiguous occurrences of na in naan with nya results in the string nyaan.
Sample Input 2
4 near
Sample Output 2
near
S may not contain a contiguous na.
Sample Input 3
8 national
Sample Output 3
nyationyal
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
6 つの面を持つサイコロが 3 個あります。
i 個目のサイコロの j 個目の面には A_{i,j} が書かれています。
どのサイコロも、各面が出る確率は \frac{1}{6} です。
これらのサイコロを同時に振ったとき、4,5,6 の書かれた目が 1 つずつ出る確率を求めてください。
制約
- A_{i,j} は 1 以上 6 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
A_{1,1} A_{1,2} A_{1,3} A_{1,4} A_{1,5} A_{1,6}
A_{2,1} A_{2,2} A_{2,3} A_{2,4} A_{2,5} A_{2,6}
A_{3,1} A_{3,2} A_{3,3} A_{3,4} A_{3,5} A_{3,6}
出力
答えを出力せよ。 真の解との絶対誤差または相対誤差が 10^{-6} 以下のとき正解とみなされる。
入力例 1
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
出力例 1
0.0277777778
求める確率は \frac{1}{36} です。 0.027778 などの出力でも正解となります。
入力例 2
4 5 6 4 5 6 4 4 5 5 6 6 6 5 4 4 5 6
出力例 2
0.2222222222
求める確率は \frac{2}{9} です。
Score : 200 points
Problem Statement
There are three dice, each with six faces.
The j-th face of the i-th die has A_{i,j} written on it.
For each die, each face comes up with probability \frac{1}{6}.
When these dice are rolled simultaneously, find the probability that the values 4,5,6 each appear exactly once.
Constraints
- A_{i,j} is an integer between 1 and 6, inclusive.
Input
The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} A_{1,3} A_{1,4} A_{1,5} A_{1,6}
A_{2,1} A_{2,2} A_{2,3} A_{2,4} A_{2,5} A_{2,6}
A_{3,1} A_{3,2} A_{3,3} A_{3,4} A_{3,5} A_{3,6}
Output
Output the answer. The answer is considered correct if the absolute or relative error from the true answer is at most 10^{-6}.
Sample Input 1
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
Sample Output 1
0.0277777778
The desired probability is \frac{1}{36}. An output such as 0.027778 is also accepted.
Sample Input 2
4 5 6 4 5 6 4 4 5 5 6 6 6 5 4 4 5 6
Sample Output 2
0.2222222222
The desired probability is \frac{2}{9}.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
マス 1, マス 2,\ldots, マス N の N 個のマスが 1 列に並んでいます。 マス i には整数 A _ i (i\le A_ i\le N) が書かれています。
s=1,2,\ldots,N のそれぞれについて、以下の問題を解いてください。
- はじめ、マス s に駒を置く。「駒が置かれているマスに書かれている整数を x として、駒をマス x に移動させる」という操作を 10 ^ {100} 回行った後、駒が置かれているマスの番号を出力する。
制約
- 1\le N\le5\times10 ^ 5
- i\le A _ i\le N\ (1\le i\le N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N
出力
s=1,2,\ldots,N に対する答えを、この順に空白を区切りとして一行に出力せよ。
入力例 1
7 2 4 7 5 5 6 7
出力例 1
5 5 7 5 5 6 7
s=1 のとき、駒は以下の図のように移動します。

駒がマス 5 に置かれているとき、操作が行われても駒は移動しないため、s=1 のときの答えは 5 となります。
入力例 2
5 1 2 3 4 5
出力例 2
1 2 3 4 5
駒が一度も移動しないこともあります。
入力例 3
15 11 3 10 7 15 10 10 11 11 13 11 12 14 14 15
出力例 3
11 14 14 14 15 14 14 11 11 14 11 12 14 14 15
Score : 300 points
Problem Statement
There are N cells, cell 1, cell 2,\ldots, cell N, arranged in a line. Cell i has an integer A_i\ (i \le A_i \le N) written on it.
For each of s=1,2,\ldots,N, solve the following problem.
- Initially, place a piece on cell s. After performing the operation "let x be the integer written on the cell where the piece is placed, and then move the piece to cell x" 10^{100} times, output the number of the cell where the piece is placed.
Constraints
- 1 \le N \le 5\times10^5
- i \le A_i \le N\ (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 \ldots A_N
Output
Output the answers for s=1,2,\ldots,N in this order on a single line, separated by spaces.
Sample Input 1
7 2 4 7 5 5 6 7
Sample Output 1
5 5 7 5 5 6 7
For s=1, the piece moves as shown in the following figure.

When the piece is placed on cell 5, the operation does not move the piece, so the answer for s=1 is 5.
Sample Input 2
5 1 2 3 4 5
Sample Output 2
1 2 3 4 5
It is possible that the piece never moves.
Sample Input 3
15 11 3 10 7 15 10 10 11 11 13 11 12 14 14 15
Sample Output 3
11 14 14 14 15 14 14 11 11 14 11 12 14 14 15