実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
0123456789 に加えて 10,11,12,13,14,15 に対応する数字として ABCDEF を使う 16 進表記では、0 以上 255 以下の整数は 1 桁または 2 桁になります。
例えば、0 や 12 は 16 進表記では 0 や C と 1 桁になり、99 や 255 は 16 進表記では 63 や FF と 2 桁になります。
0 以上 255 以下の整数 N を、必要に応じて先頭に 0 を加えることでちょうど 2 桁の 16 進表記に変換してください。
注記
英大文字と英小文字は区別されます。特に、16 進表記の数字として ABCDEF の代わりに abcdef を使うことは出来ません。
制約
- 0 \leq N \leq 255
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
99
出力例 1
63
99 は 16 進表記で 63 です。
入力例 2
12
出力例 2
0C
12 は 16 進表記で C です。
要求されているのはちょうど 2 桁の 16 進表記に変換することなので、C の先頭に 0 を加えた 0C が答えです。
入力例 3
0
出力例 3
00
入力例 4
255
出力例 4
FF
Score : 100 points
Problem Statement
In the hexadecimal system, where the digits ABCDEF corresponding to 10,11,12,13,14, and 15 are used in addition to 0123456789, every integer between 0 and 255 is represented as a 1- or 2-digit numeral.
For example, 0 and 12 are represented as 1-digit hexadecimal numerals 0 and C; 99 and 255 are represented as 2-digit hexadecimals 63 and FF.
Given an integer N between 0 and 255, convert it to an exactly two-digit hexadecimal numeral, prepending leading 0s if necessary.
Notes
The judge is case-sensitive. Specifically, you cannot use abcdef as hexadecimal digits instead of ABCDEF.
Constraints
- 0 \leq N \leq 255
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
99
Sample Output 1
63
99 is represented as 63 in hexadecimal.
Sample Input 2
12
Sample Output 2
0C
12 is represented as C in hexadecimal.
Since we ask you to convert it to a two-digit hexadecimal numeral, the answer is 0C, where 0 is prepended to C.
Sample Input 3
0
Sample Output 3
00
Sample Input 4
255
Sample Output 4
FF
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君はある会社の採用面接を受けました。
面接官の人数 N と、各面接官の高橋君への評価を表す長さ N の文字列 S が与えられます。
i=1,2,\ldots,N に対し S の i 文字目が i 番目の面接官の評価に対応し、o は「良」、- は「可」、x は 「不可」を表します。
高橋君は以下の 2 つの条件を両方満たすならば合格、そうでなければ不合格です。
- 「良」と評価した面接官が少なくとも 1 人いる
- 「不可」と評価した面接官がいない
高橋君が合格かどうかを判定してください。
制約
- 1 \leq N \leq 100
- S は
o,-,xのみからなる長さが N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
高橋君が合格ならば Yes と、そうでなければ No と出力せよ。
入力例 1
4 oo--
出力例 1
Yes
1, 2 番目の面接官が「良」と評価していて、さらに「不可」と評価した面接官がいないため合格です。
入力例 2
3 ---
出力例 2
No
「良」と評価した面接官が 1 人もいないため不合格です。
入力例 3
1 o
出力例 3
Yes
入力例 4
100 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooox
出力例 4
No
100 番目の面接官が「不可」と評価しているため不合格です。
Score : 100 points
Problem Statement
Takahashi had a job interview.
You are given the number of interviewers, N, and a string S of length N representing the interviewers' evaluations of him.
For each i=1,2,\ldots,N, the i-th character of S corresponds to the i-th interviewer's evaluation; o means Good, - means Fair, and x means Poor.
Takahashi will pass if both of the following conditions are satisfied, and fail otherwise.
- At least one interviewer's evaluation is Good.
- No interviewer's evaluation is Poor.
Determine whether Takahashi passes.
Constraints
- 1 \leq N \leq 100
- S is a string of length N consisting of
o,-, andx.
Input
The input is given from Standard Input in the following format:
N S
Output
If Takahashi passes, print Yes; otherwise, print No.
Sample Input 1
4 oo--
Sample Output 1
Yes
The first and second interviewers' evaluations are Good, and no interviewer's evaluation is Poor, so he passes.
Sample Input 2
3 ---
Sample Output 2
No
No interviewer's evaluation is Good, so he fails.
Sample Input 3
1 o
Sample Output 3
Yes
Sample Input 4
100 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooox
Sample Output 4
No
The 100-th interviewer's evaluation is Poor, so he fails.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
0 と 1 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。
制約
- A_i は 0 または 1
入力
入力は以下の形式で標準入力から与えられる。
A_0 A_1 \dots A_{63}
出力
答えを整数として出力せよ。
入力例 1
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
出力例 1
13
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13 です。
入力例 2
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0
出力例 2
766067858140017173
Score : 200 points
Problem Statement
You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1.
Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}.
Constraints
- A_i is 0 or 1.
Input
The input is given from Standard Input in the following format:
A_0 A_1 \dots A_{63}
Output
Print the answer as an integer.
Sample Input 1
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 1
13
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13.
Sample Input 2
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0
Sample Output 2
766067858140017173
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 個のマスが左右一列に並んでおり、左から順にマス 1、マス 2、…、マス N と番号づけられています。
また、K 個のコマがあり、最初左から i 番目のコマはマス A_i に置かれています。
これらに対して、Q 回の操作を行います。
i 回目の操作では次の操作を行います。
- 左から L_i 番目のコマが一番右のマスにあるならば何も行わない。
- そうでない時、左から L_i 番目のコマがあるマスの 1 つ右のマスにコマが無いならば、左から L_i 番目のコマを 1 つ右のマスに移動させる。 1 つ右のマスにコマがあるならば、何も行わない。
Q 回の操作が終了した後の状態について、i=1,2,\ldots,K に対して左から i 番目のコマがあるマスの番号を出力してください。
制約
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
出力
K 個の整数を空白区切りで一行に出力せよ。 ここで、i 個目の整数は、 Q 回の操作が終了した後の状態について、左から i 番目のコマの番号を表す。
入力例 1
5 3 5 1 3 4 3 3 1 1 2
出力例 1
2 4 5
最初、コマはマス 1, 3, 4 にあります。これに対して以下のように操作が行われます。
- 左から 3 番目のコマはマス 4 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 3 番目のコマをマス 5 に動かします。 コマはマス 1, 3, 5 にある状態になります。
- 左から 3 番目のコマはマス 5 にあります。 これは一番右のマスなので、何も行いません。 コマはマス 1, 3, 5 にある状態のままです。
- 左から 1 番目のコマはマス 1 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 1 番目のコマをマス 2 に動かします。 コマはマス 2, 3, 5 にある状態になります。
- 左から 1 番目のコマはマス 2 にあります。 これは一番右のマスでありませんが、その 1 つ右のマス(マス 3 )にコマが置かれているため、何も行いません。 コマはマス 2, 3, 5 にある状態のままです。
- 左から 2 番目のコマはマス 3 にあります。 これは一番右のマスでなく、その右のマスにもコマが置かれていないため、左から 2 番目のコマをマス 4 に動かします。 コマはマス 2, 4, 5 にある状態になります。
よって、Q 回の操作が終わった後でコマはマス 2, 4, 5 に置かれているため、2,4,5 を空白区切りでこの順に出力します。
入力例 2
2 2 2 1 2 1 2
出力例 2
1 2
入力例 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
出力例 3
2 5 6 7 9 10
Score : 200 points
Problem Statement
There are N squares, indexed Square 1, Square 2, …, Square N, arranged in a row from left to right.
Also, there are K pieces. The i-th piece from the left is initially placed on Square A_i.
Now, we will perform Q operations against them.
The i-th operation is as follows:
- If the L_i-th piece from the left is on its rightmost square, do nothing.
- Otherwise, move the L_i-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the i-th piece from the left is after the Q operations have ended, for each i=1,2,\ldots,K.
Constraints
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
Output
Print K integers in one line, with spaces in between. The i-th of them should be the index of the square on which the i-th piece from the left is after the Q operations have ended.
Sample Input 1
5 3 5 1 3 4 3 3 1 1 2
Sample Output 1
2 4 5
At first, the pieces are on Squares 1, 3, and 4. The operations are performed against them as follows:
- The 3-rd piece from the left is on Square 4. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 3-rd piece from the left to Square 5. Now, the pieces are on Squares 1, 3, and 5.
- The 3-rd piece from the left is on Square 5. This is the rightmost square, so do nothing. The pieces are still on Squares 1, 3, and 5.
- The 1-st piece from the left is on Square 1. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 1-st piece from the left to Square 2. Now, the pieces are on Squares 2, 3, and 5.
- The 1-st piece from the left is on Square 2. This is not the rightmost square, but the next square on the right (Square 3) contains a piece, so do nothing. The pieces are still on Squares 2, 3, and 5.
- The 2-nd piece from the left is on Square 3. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 2-nd piece from the left to Square 4; Now, the pieces are still on Squares 2, 4, and 5.
Thus, after the Q operations have ended, the pieces are on Squares 2, 4, and 5, so 2, 4, and 5 should be printed in this order, with spaces in between.
Sample Input 2
2 2 2 1 2 1 2
Sample Output 2
1 2
Sample Input 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
Sample Output 3
2 5 6 7 9 10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 N が与えられます。
正整数の組 (A,B,C,D) であって、AB + CD = N を満たすものの個数を求めてください。
なお、本問の制約の下、答えが 9 \times 10^{18} 以下であることが証明できます。
制約
- 2 \leq N \leq 2 \times 10^5
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
4
出力例 1
8
(A,B,C,D) として以下の 8 個が考えられます。
- (A,B,C,D)=(1,1,1,3)
- (A,B,C,D)=(1,1,3,1)
- (A,B,C,D)=(1,2,1,2)
- (A,B,C,D)=(1,2,2,1)
- (A,B,C,D)=(1,3,1,1)
- (A,B,C,D)=(2,1,1,2)
- (A,B,C,D)=(2,1,2,1)
- (A,B,C,D)=(3,1,1,1)
入力例 2
292
出力例 2
10886
入力例 3
19876
出力例 3
2219958
Score : 300 points
Problem Statement
You are given a positive integer N.
Find the number of quadruples of positive integers (A,B,C,D) such that AB + CD = N.
Under the constraints of this problem, it can be proved that the answer is at most 9 \times 10^{18}.
Constraints
- 2 \leq N \leq 2 \times 10^5
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
4
Sample Output 1
8
Here are the eight desired quadruples.
- (A,B,C,D)=(1,1,1,3)
- (A,B,C,D)=(1,1,3,1)
- (A,B,C,D)=(1,2,1,2)
- (A,B,C,D)=(1,2,2,1)
- (A,B,C,D)=(1,3,1,1)
- (A,B,C,D)=(2,1,1,2)
- (A,B,C,D)=(2,1,2,1)
- (A,B,C,D)=(3,1,1,1)
Sample Input 2
292
Sample Output 2
10886
Sample Input 3
19876
Sample Output 3
2219958
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A=(a_1,\ldots,a_N) があります。また、整数 K が与えられます。
あなたは次の操作を 0 回以上何度でも行えます。
- 1 \leq i \leq N-K を満たす整数 i を選び、a_i と a_{i+K} の値を入れ替える。
A を昇順に並べ替えることが出来るかどうかを判定してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K a_1 \ldots a_N
出力
A を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。
入力例 1
5 2 3 4 1 3 4
出力例 1
Yes
次のように操作をすることで A を昇順に並び替えることが出来ます。
- i=1 とし、a_1 と a_3 の値を入れ替える。数列は (1,4,3,3,4) となる。
- i=2 とし、a_2 と a_4 の値を入れ替える。数列は (1,3,3,4,4) となる。
入力例 2
5 3 3 4 1 3 4
出力例 2
No
入力例 3
7 5 1 2 3 4 5 5 10
出力例 3
Yes
操作を行う必要が無い場合もあります。
Score : 300 points
Problem Statement
We have a sequence of length N: A=(a_1,\ldots,a_N). Additionally, you are given an integer K.
You can perform the following operation zero or more times.
- Choose an integer i such that 1 \leq i \leq N-K, then swap the values of a_i and a_{i+K}.
Determine whether it is possible to sort A in ascending order.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K a_1 \ldots a_N
Output
If it is possible to sort A in ascending order, print Yes; otherwise, print No.
Sample Input 1
5 2 3 4 1 3 4
Sample Output 1
Yes
The following sequence of operations sorts A in ascending order.
- Choose i=1 to swap the values of a_1 and a_3. A is now (1,4,3,3,4).
- Choose i=2 to swap the values of a_2 and a_4. A is now (1,3,3,4,4).
Sample Input 2
5 3 3 4 1 3 4
Sample Output 2
No
Sample Input 3
7 5 1 2 3 4 5 5 10
Sample Output 3
Yes
No operations may be needed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
T 個のテストケースについて、以下の問題を解いてください。
非負整数 a,s が与えられます。以下の条件を両方とも満たす非負整数の組 (x,y) は存在しますか?
- x\ \text{AND}\ y=a
- x+y=s
\text{AND} とは
非負整数 n, m の bit ごとの論理積 n\ \text{AND}\ m は、以下のように定義されます。
- n\ \text{AND}\ m を二進表記した際の 2^k \, (k \geq 0) の位の数は、n, m を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1、そうでなければ 0 である。
制約
- 1 \leq T \leq 10^5
- 0 \leq a,s \lt 2^{60}
- 入力はすべて整数
入力
入力は標準入力から与えられる。入力の 1 行目は以下の形式である。
T
その後、 T 個のテストケースが続く。各テストケースは以下の形式で与えられる。
a s
出力
T 行出力せよ。i\ (1 \leq i \leq T) 行目には、i 番目に与えられるテストケースについて問題文中の条件を両方とも満たす非負整数の組 (x,y) が存在するなら Yes を、存在しないなら No を出力せよ。
入力例 1
2 1 8 4 2
出力例 1
Yes No
1 番目のテストケースにおいては、(x,y)=(3,5) などが条件を満たします。
2 番目のテストケースにおいては、条件を満たす非負整数の組 (x,y) は存在しません。
入力例 2
4 201408139683277485 381410962404666524 360288799186493714 788806911317182736 18999951915747344 451273909320288229 962424162689761932 1097438793187620758
出力例 2
No Yes Yes No
Score : 400 points
Problem Statement
Solve the following problem for T test cases.
Given are non-negative integers a and s. Is there a pair of non-negative integers (x,y) that satisfies both of the conditions below?
- x\ \text{AND}\ y=a
- x+y=s
What is bitwise \mathrm{AND}?
The bitwise \mathrm{AND} of integers A and B, A\ \mathrm{AND}\ B, is defined as follows:
- When A\ \mathrm{AND}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if those of A and B are both 1, and 0 otherwise.
Constraints
- 1 \leq T \leq 10^5
- 0 \leq a,s \lt 2^{60}
- All values in input are integers.
Input
Input is given from Standard Input. The first line is in the following format:
T
Then, T test cases follow. Each test case is in the following format:
a s
Output
Print T lines. The i-th line (1 \leq i \leq T) should contain Yes if, in the i-th test case, there is a pair of non-negative integers (x,y) that satisfies both of the conditions in the Problem Statement, and No otherwise.
Sample Input 1
2 1 8 4 2
Sample Output 1
Yes No
In the first test case, some pairs such as (x,y)=(3,5) satisfy the conditions.
In the second test case, no pair of non-negative integers satisfies the conditions.
Sample Input 2
4 201408139683277485 381410962404666524 360288799186493714 788806911317182736 18999951915747344 451273909320288229 962424162689761932 1097438793187620758
Sample Output 2
No Yes Yes No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。ここで、各 A_i (1\leq i\leq N) は 1\leq A_i \leq N をみたします。
高橋君と青木君が N 回ゲームを行います。i=1,2,\ldots,N 回目のゲームは次のようにして行われます。
- 青木君が正整数 K_i を指定する。
- 青木君の指定した K_i を聞いた後、高橋君は 1 以上 N 以下の整数 S_i を選び、黒板に書く。
-
その後、 K_i 回次の操作を繰り返す。
- 黒板に x が書かれているとき、それを消し、A_x を新しく書く。
K_i 回の操作の後で黒板に書かれている整数が i ならば i 回目のゲームは高橋君の勝ち、そうでないならば青木君の勝ちとなります。
ここで、K_i,S_i は i=1,2,\ldots,N に対して独立に選ぶ事ができます。
両者が、自身が勝つために最善の行動をとったとき、N 回のゲームのうち高橋君が勝つ回数を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
両者が最善の行動をとったとき、N 回のゲームのうち高橋君が勝つ回数を出力せよ。
入力例 1
3 2 2 3
出力例 1
2
1 回目のゲームにおいて、青木君が K_1=2 を指定したとき、高橋君は S_1 として、1,2,3 のいずれを選んでも勝つことはできません。
例えば、高橋君が最初に黒板に S_1=1 と書いたとすると、2 回の操作で黒板に書かれている数は順に 1\to 2(=A_1) 、2\to 2(=A_2) と変化し、
最終的に黒板に書かれている数は 2(\neq 1) であるため、青木君の勝ちとなります。
一方、2,3 回目のゲームにおいては、青木君の指定した K_i の値によらず、高橋君はそれぞれ 2,3 を最初に黒板に書くことで勝つ事ができます。
よって、両者が、自分が勝つために最善の行動をとったとき、高橋君が勝つゲームは 2,3 回目の 2 回であるため、2 を出力します。
入力例 2
2 2 1
出力例 2
2
1 回目のゲームにおいて、高橋君は、青木君が指定した K_1 が奇数のときは 2、偶数のときは 1 を最初に黒板に書く事で勝つ事ができます。
同様に 2 回目のゲームにおいても勝つ方法が存在するため、1,2 回目のゲームのいずれでも高橋君は勝利する事ができ、2 が答えとなります。
Score : 500 points
Problem Statement
You are given a sequence of N numbers: A=(A_1,A_2,\ldots,A_N). Here, each A_i (1\leq i\leq N) satisfies 1\leq A_i \leq N.
Takahashi and Aoki will play N rounds of a game. For each i=1,2,\ldots,N, the i-th game will be played as follows.
- Aoki specifies a positive integer K_i.
- After knowing K_i Aoki has specified, Takahashi chooses an integer S_i between 1 and N, inclusive, and writes it on a blackboard.
-
Repeat the following K_i times.
- Replace the integer x written on the blackboard with A_x.
If i is written on the blackboard after the K_i iterations, Takahashi wins the i-th round; otherwise, Aoki wins.
Here, K_i and S_i can be chosen independently for each i=1,2,\ldots,N.
Find the number of rounds Takahashi wins if both players play optimally to win.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq N
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Find the number of rounds Takahashi wins if both players play optimally to win.
Sample Input 1
3 2 2 3
Sample Output 1
2
In the first round, if Aoki specifies K_1=2, Takahashi cannot win whichever option he chooses for S_1: 1, 2, or 3.
For example, if Takahashi writes S_1=1 on the initial blackboard, the two operations will change this number as follows: 1\to 2(=A_1), 2\to 2(=A_2). The final number on the blackboard will be 2(\neq 1), so Aoki wins.
On the other hand, in the second and third rounds, Takahashi can win by writing 2 and 3, respectively, on the initial blackboard, whatever value Aoki specifies as K_i.
Therefore, if both players play optimally to win, Takashi wins two rounds: the second and the third. Thus, you should print 2.
Sample Input 2
2 2 1
Sample Output 2
2
In the first round, Takahashi can win by writing 2 on the initial blackboard if K_1 specified by Aoki is odd, and 1 if it is even.
Similarly, there is a way for Takahashi to win the second round. Thus, Takahashi can win both rounds: the answer is 2.
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 行 N 列のマス目があり、上から i \, (1 \leq i \leq N) 行目、左から j \, (1 \leq j \leq N) 列目のマスを (i, j) と表します。
マス (i, j) には非負整数 a_{i, j} が書かれています。
マス (i, j) にいるとき、マス (i+1, j), (i, j+1) のいずれかに移動することができます。ただし、マス目の外に出るような移動はできません。
マス (1, 1) から移動を繰り返してマス (N, N) にたどり着く方法であって、通ったマス(マス (1, 1), (N, N) を含む)に書かれた整数の排他的論理和が 0 となるようなものの総数を求めてください。
排他的論理和とは
整数 a, b の排他的論理和 a \oplus b は、以下のように定義されます。- a \oplus b を二進表記した際の 2^k \, (k \geq 0) の位の数は、a, b を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
一般に k 個の整数 p_1, \dots, p_k の排他的論理和は (\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k) と定義され、これは p_1, \dots, p_k の順番によらないことが証明できます。
制約
- 2 \leq N \leq 20
- 0 \leq a_{i, j} \lt 2^{30} \, (1 \leq i, j \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
a_{1, 1} \ldots a_{1, N}
\vdots
a_{N, 1} \ldots a_{N, N}
出力
答えを出力せよ。
入力例 1
3 1 5 2 7 0 5 4 2 3
出力例 1
2
次の二通りの方法が条件を満たします。
- (1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3)
- (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)
入力例 2
2 1 2 2 1
出力例 2
0
入力例 3
10 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 0
出力例 3
24307
Score : 500 points
Problem Statement
There is a grid with N rows and N columns. We denote by (i, j) the square at the i-th (1 \leq i \leq N) row from the top and j-th (1 \leq j \leq N) column from the left.
Square (i, j) has a non-negative integer a_{i, j} written on it.
When you are at square (i, j), you can move to either square (i+1, j) or (i, j+1). Here, you are not allowed to go outside the grid.
Find the number of ways to travel from square (1, 1) to square (N, N) such that the exclusive logical sum of the integers written on the squares visited (including (1, 1) and (N, N)) is 0.
What is the exclusive logical sum?
The exclusive logical sum a \oplus b of two integers a and b is defined as follows.- The 2^k's place (k \geq 0) in the binary notation of a \oplus b is 1 if exactly one of the 2^k's places in the binary notation of a and b is 1; otherwise, it is 0.
In general, the exclusive logical sum of k integers p_1, \dots, p_k is defined as (\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k). We can prove that it is independent of the order of p_1, \dots, p_k.
Constraints
- 2 \leq N \leq 20
- 0 \leq a_{i, j} \lt 2^{30} \, (1 \leq i, j \leq N)
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
a_{1, 1} \ldots a_{1, N}
\vdots
a_{N, 1} \ldots a_{N, N}
Output
Print the answer.
Sample Input 1
3 1 5 2 7 0 5 4 2 3
Sample Output 1
2
The following two ways satisfy the condition:
- (1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3);
- (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3).
Sample Input 2
2 1 2 2 1
Sample Output 2
0
Sample Input 3
10 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 0
Sample Output 3
24307