実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋くんは A グラムの純金と B グラムの純銀 (0 \leq A,B,\ 0 \lt A+B) をよく溶かした上で混ぜ合わせ、新たな金属を生成しました。
生成された金属は「純金」「純銀」「合金」のいずれでしょうか?
なお、生成された金属は
- 0 \lt A かつ B=0 なら「純金」
- A=0 かつ 0 \lt B なら「純銀」
- 0 \lt A かつ 0 \lt B なら「合金」
であるとみなします。
制約
- 0 \leq A,B \leq 100
- 0 \lt A+B
- A,B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
生成された金属が「純金」なら Gold と、「純銀」なら Silver と、「合金」なら Alloy と出力せよ。
入力例 1
50 50
出力例 1
Alloy
0 \lt A かつ 0 \lt B であるため、生成された金属は「合金」です。
入力例 2
100 0
出力例 2
Gold
0 \lt A かつ B=0 であるため、生成された金属は「純金」です。
入力例 3
0 100
出力例 3
Silver
A=0 かつ 0 \lt B であるため、生成された金属は「純銀」です。
入力例 4
100 2
出力例 4
Alloy
Score : 100 points
Problem Statement
Takahashi melted and mixed A grams of gold and B grams of silver (0 \leq A,B,\ 0 \lt A+B) to produce new metal.
What metal did he produce: pure gold, pure silver, or an alloy?
Formally, the product is called as follows.
- Pure gold, if 0 \lt A and B=0.
- Pure silver, if A=0 and 0 \lt B.
- An alloy, if 0 \lt A and 0 \lt B.
Constraints
- 0 \leq A,B \leq 100
- 1 \leq A+B
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
If the product is pure gold, print Gold; if it is pure silver, print Silver; if it is an alloy, print Alloy.
Sample Input 1
50 50
Sample Output 1
Alloy
We have 0 \lt A and 0 \lt B, so the product is an alloy.
Sample Input 2
100 0
Sample Output 2
Gold
We have 0 \lt A and B=0, so the product is pure gold.
Sample Input 3
0 100
Sample Output 3
Silver
We have A=0 and 0 \lt B, so the product is pure silver.
Sample Input 4
100 2
Sample Output 4
Alloy
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は N 歳の誕生日を迎えました。この時の彼の身長は T cmです。
また、以下のことが分かっています。
- 高橋君は 0 歳の誕生日(生まれた当日)から X 歳の誕生日までの間、毎年身長が D cmずつ伸びた。より厳密に書くと、i=1,2,\ldots,X それぞれに対し、i-1 歳の誕生日から i 歳の誕生日までの間に身長が D cm伸びた。
- 高橋君は X 歳の誕生日から N 歳の誕生日までの間、身長が変化していない。
高橋君の M 歳の誕生日の時の身長が何cmだったかを求めてください。
制約
- 0 \leq M \lt N \leq 100
- 1 \leq X \leq N
- 1 \leq T \leq 200
- 1 \leq D \leq 100
- 高橋君の 0 歳の誕生日の時の身長は 1 cm以上である
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M X T D
出力
答えを整数として出力せよ。
入力例 1
38 20 17 168 3
出力例 1
168
この例では、高橋君の 38 歳の誕生日の時の身長が 168 cmです。また、17 歳の誕生日から 38 歳の誕生日までの間、身長が変化していません。
このことから、20 歳の誕生日の時の身長は 168 cmだったと言え、これが答えになります。
入力例 2
1 0 1 3 2
出力例 2
1
この例において、高橋君は 0(=M) 歳の誕生日の時の身長が 1 cmで、1(=N) 歳の誕生日の時の身長が 3(=T) cmです。
入力例 3
100 10 100 180 1
出力例 3
90
Score : 100 points
Problem Statement
Takahashi had his N-th birthday, when he was T centimeters tall.
Additionally, we know the following facts:
- In each year between Takahashi's birth (0-th birthday) and his X-th birthday, his height increased by D centimeters. More formally, for each i = 1, 2, \ldots, X, his height increased by D centimeters between his (i-1)-th birthday and his i-th birthday.
- Between Takahashi's X-th birthday and his N-th birthday, his height did not change.
Find Takahashi's height on his M-th birthday, in centimeters.
Constraints
- 0 \leq M \lt N \leq 100
- 1 \leq X \leq N
- 1 \leq T \leq 200
- 1 \leq D \leq 100
- Takahashi was at least 1 centimeter tall at his birth.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M X T D
Output
Print the answer as an integer.
Sample Input 1
38 20 17 168 3
Sample Output 1
168
In this sample, Takahashi was 168 centimeters tall on his 38-th birthday. Also, his height did not change between his 17-th birthday and 38-th birthday.
From these facts, we find that he was 168 centimeters tall on his 20-th birthday, so the answer is 168.
Sample Input 2
1 0 1 3 2
Sample Output 2
1
In this sample, Takahashi was 1 centimeter tall on his 0(=M)-th birthday and 3(=T) centimeters tall on his 1(=N)-st birthday.
Sample Input 3
100 10 100 180 1
Sample Output 3
90
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
プレイヤー 1 、プレイヤー 2 、\ldots 、プレイヤー N と番号がつけられた N 人のプレイヤーがカードゲームで対戦します。
各プレイヤーはカードを 1 枚場に出します。
各カードは色と値の 2 つの属性を持ち、どちらの属性も正整数で表されます。
i = 1, 2, \ldots, N について、プレイヤー i が場に出したカードの色は C_i であり、値は R_i です。
R_1, R_2, \ldots, R_N はすべて異なります。
N 人のプレイヤーの中から 1 人の勝者を下記の方法で決めます。
- 色が T であるカードが 1 枚以上場に出された場合、色が T であるカードのうち値が最大のものを出したプレイヤーが勝者である。
- 色が T であるカードが場に 1 枚も出されなかった場合、プレイヤー 1 が出したカードと同じ色のカードのうち値が最大のものを出したプレイヤーが勝者である。(プレイヤー 1 自身も勝者となり得ることに注意してください。)
勝者となるプレイヤーの番号を出力してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq R_i \leq 10^9
- i \neq j \implies R_i \neq R_j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T C_1 C_2 \ldots C_N R_1 R_2 \ldots R_N
出力
答えを出力せよ。
入力例 1
4 2 1 2 1 2 6 3 4 5
出力例 1
4
色が 2 であるカードが 1 枚以上場に出されています。 よって、色が 2 であるカードのうち値が最大の 5 のカードを出した、プレイヤー 4 が勝者です。
入力例 2
4 2 1 3 1 4 6 3 4 5
出力例 2
1
色が 2 であるカードが 1 枚も場に出されていません。 よって、プレイヤー 1 が出したカードの色と同じ色(すなわち色 1 )のカードのうち値が最大の 6 のカードを出した、プレイヤー 1 が勝者です。
入力例 3
2 1000000000 1000000000 1 1 1000000000
出力例 3
1
Score : 200 points
Problem Statement
N players with ID numbers 1, 2, \ldots, N are playing a card game.
Each player plays one card.
Each card has two parameters: color and rank, both of which are represented by positive integers.
For i = 1, 2, \ldots, N, the card played by player i has a color C_i and a rank R_i.
All of R_1, R_2, \ldots, R_N are different.
Among the N players, one winner is decided as follows.
- If one or more cards with the color T are played, the player who has played the card with the greatest rank among those cards is the winner.
- If no card with the color T is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 1 is the winner. (Note that player 1 may win.)
Print the ID number of the winner.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq R_i \leq 10^9
- i \neq j \implies R_i \neq R_j
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N T C_1 C_2 \ldots C_N R_1 R_2 \ldots R_N
Output
Print the answer.
Sample Input 1
4 2 1 2 1 2 6 3 4 5
Sample Output 1
4
Cards with the color 2 are played. Thus, the winner is player 4, who has played the card with the greatest rank, 5, among those cards.
Sample Input 2
4 2 1 3 1 4 6 3 4 5
Sample Output 2
1
No card with the color 2 is played. Thus, the winner is player 1, who has played the card with the greatest rank, 6, among the cards with the color of the card played by player 1 (color 1).
Sample Input 3
2 1000000000 1000000000 1 1 1000000000
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
縦 H マス \times 横 W マスのマス目があり、各マスに 1 つずつ英小文字が書き込まれています。 上から i 行目かつ左から j 列目のマスを (i,j) で表します。
マス目に書き込まれている英小文字は H 個の長さ W の文字列 S_1,S_2,\ldots, S_H によって与えられ、 S_i の j 文字目が、(i, j) に書き込まれた英小文字を表します。
マス目の中に、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる
場所がただ 1 つ存在します。
そのような場所を見つけ、そのマスの位置を出力の形式に従って出力してください。
ただし、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる場所とは、
5 つのマスの組 (A_1,A_2,A_3,A_4,A_5) であって、次をすべてみたすものをさします。
- A_1,A_2,A_3,A_4,A_5 に書き込まれた英小文字はそれぞれ
s,n,u,k,eである。 - 1\leq i\leq 4 について、A_i と A_{i+1} は頂点または辺を共有している。
- A_1,A_2,A_3,A_4,A_5 の中心はこの順に一直線上に等間隔で並んでいる。
制約
- 5\leq H\leq 100
- 5\leq W\leq 100
- H,W は整数
- S_i は英小文字のみからなる長さ W の文字列
- 与えられるマス目の中に条件をみたす場所がただ 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
次の形式にしたがって、5 行出力せよ。
条件をみたす場所のうち s, n, u, k, e が書かれたマスがそれぞれ (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) であるとき、
i 行目には R_i と C_i をこの順に空白区切りで出力せよ。
すなわち、以下のように出力せよ。
R_1 C_1 R_2 C_2 \vdots R_5 C_5
以下の入力例も参考にせよ。
入力例 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
出力例 1
5 2 5 3 5 4 5 5 5 6
この時、(A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) とすると、
それぞれのマスに書き込まれた英小文字は s, n, u, k, e であり、
1\leq i\leq 4 について、A_i と A_{i+1} は辺を共有しており、
各マスの中心は一直線上に存在するため、条件をみたしています。

入力例 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
出力例 2
5 5 4 4 3 3 2 2 1 1
(A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) が条件をみたしています。
例えば、(A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) は、1,2 つめの条件をみたしていますが、
マスの中心が一直線上に存在しないため、3 つめの条件をみたしていません。
入力例 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
出力例 3
9 3 8 3 7 3 6 3 5 3
Score : 250 points
Problem Statement
There is a grid with H horizontal rows and W vertical columns. Each cell has a lowercase English letter written on it. We denote by (i, j) the cell at the i-th row from the top and j-th column from the left.
The letters written on the grid are represented by H strings S_1,S_2,\ldots, S_H, each of length W. The j-th letter of S_i represents the letter written on (i, j).
There is a unique set of
contiguous cells (going vertically, horizontally, or diagonally) in the grid
with s, n, u, k, and e written on them in this order.
Find the positions of such cells and print them in the format specified in the Output section.
A tuple of five cells (A_1,A_2,A_3,A_4,A_5) is said to form
a set of contiguous cells (going vertically, horizontally, or diagonally) with s, n, u, k, and e written on them in this order
if and only if all of the following conditions are satisfied.
- A_1,A_2,A_3,A_4 and A_5 have letters
s,n,u,k, andewritten on them, respectively. - For all 1\leq i\leq 4, cells A_i and A_{i+1} share a corner or a side.
- The centers of A_1,A_2,A_3,A_4, and A_5 are on a common line at regular intervals.
Constraints
- 5\leq H\leq 100
- 5\leq W\leq 100
- H and W are integers.
- S_i is a string of length W consisting of lowercase English letters.
- The given grid has a unique conforming set of cells.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print five lines in the following format.
Let (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) be the cells in the sought set with s, n, u, k, and e written on them, respectively.
The i-th line should contain R_i and C_i in this order, separated by a space.
In other words, print them in the following format:
R_1 C_1 R_2 C_2 \vdots R_5 C_5
See also Sample Inputs and Outputs below.
Sample Input 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
Sample Output 1
5 2 5 3 5 4 5 5 5 6
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) satisfies the conditions.
Indeed, the letters written on them are s, n, u, k, and e;
for all 1\leq i\leq 4, cells A_i and A_{i+1} share a side;
and the centers of the cells are on a common line.

Sample Input 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
Sample Output 2
5 5 4 4 3 3 2 2 1 1
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) satisfies the conditions.
However, for example, (A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) violates the third condition because the centers of the cells are not on a common line, although it satisfies the first and second conditions.
Sample Input 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
Sample Output 3
9 3 8 3 7 3 6 3 5 3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字のみからなる N 個の文字列 S_1,S_2,\dots,S_N が与えられます。
S_1,S_2,\dots,S_N から文字列を好きな個数選ぶことを考えます。
このとき、「選んだ文字列の中でちょうど K 個の文字列に登場する英小文字」の種類数としてあり得る最大値を求めてください。
制約
- 1 \le N \le 15
- 1 \le K \le N
- N,K は整数
- S_i は英小文字からなる空でない文字列である。
- 1 \le i \le N を満たす整数 i に対し、S_i に同じ文字は 2 個以上含まれない。
- i \neq j ならば S_i \neq S_j である。
入力
入力は以下の形式で標準入力から与えられる。
N K S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
4 2 abi aef bc acg
出力例 1
3
S_1,S_3,S_4 を選んだ場合、a,b,c がちょうど 2 個の文字列に含まれます。
4 個以上の文字がちょうど 2 個の文字列に含まれるような選び方は存在しないため、答えは 3 です。
入力例 2
2 2 a b
出力例 2
0
同じ文字列を複数回選ぶことはできません。
入力例 3
5 2 abpqxyz az pq bc cy
出力例 3
7
Score : 300 points
Problem Statement
You are given N strings S_1,S_2,\dots,S_N consisting of lowercase English alphabets.
Consider choosing some number of strings from S_1,S_2,\dots,S_N.
Find the maximum number of distinct alphabets that satisfy the following condition: "the alphabet is contained in exactly K of the chosen strings."
Constraints
- 1 \le N \le 15
- 1 \le K \le N
- N and K are integers.
- S_i is a non-empty string consisting of lowercase English alphabets.
- For each integer i such that 1 \le i \le N, S_i does not contain two or more same alphabets.
- If i \neq j, then S_i \neq S_j.
Input
Input is given from Standard Input in the following format:
N K S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
4 2 abi aef bc acg
Sample Output 1
3
When S_1,S_3, and S_4 are chosen, a,b, and c occur in exactly two of the strings.
There is no way to choose strings so that 4 or more alphabets occur in exactly 2 of the strings, so the answer is 3.
Sample Input 2
2 2 a b
Sample Output 2
0
You cannot choose the same string more than once.
Sample Input 3
5 2 abpqxyz az pq bc cy
Sample Output 3
7
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
1 から N までの番号がついた N 個の空の箱と、何も書かれていない無数のカードがあります。
Q 個のクエリが与えられるので、順番に処理してください。クエリは次の 3 種類のいずれかです。
1 i j\colon カードを 1 枚選んで数 i を書き込み、そのカードを箱 j に入れる2 i\colon 箱 i に入っているカードに書かれた数を昇順ですべて答える3 i\colon 数 i が書かれたカードが入っている箱の番号を昇順ですべて答える
ただし、以下の点に注意してください。
- 2 番目の形式のクエリにおいては、箱 i の中に同じ数が書かれたカードが複数枚あるときは、入っている枚数と同じ回数だけその数を出力する
- 3 番目の形式のクエリにおいては、数 i が書かれたカードが同じ箱に複数枚入っている場合でも、その箱の番号は 1 度だけ出力する
制約
- 1 \leq N, Q \leq 2 \times 10^5
- 1 番目の形式のクエリについて、
- 1 \leq i \leq 2 \times 10^5
- 1 \leq j \leq N
- 2 番目の形式のクエリについて、
- 1 \leq i \leq N
- このクエリが与えられる時点で箱 i にカードが入っている
- 3 番目の形式のクエリについて、
- 1 \leq i \leq 2 \times 10^5
- このクエリが与えられる時点で数 i が書かれたカードが入っている箱が存在する
- 出力するべき数は合計で 2 \times 10^5 個以下
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
ただし、\mathrm{query}_q は q 個目のクエリを表しており、次のいずれかの形式で与えられる。
1 i j
2 i
3 i
出力
2 番目の形式のクエリと 3 番目の形式のクエリに対し、順番に答えを出力せよ。
各クエリでは出力するべき要素を昇順に空白区切りで出力し、クエリごとに改行せよ。
入力例 1
5 8 1 1 1 1 2 4 1 1 4 2 4 1 1 4 2 4 3 1 3 2
出力例 1
1 2 1 1 2 1 4 4
クエリを順に処理していきます。
- カードに 1 を書き込み、箱 1 に入れます。
- カードに 2 を書き込み、箱 4 に入れます。
- カードに 1 を書き込み、箱 4 に入れます。
- 箱 4 に入っているカードに書かれた数は 1, 2 です。
- 1, 2 の順に出力してください。
- カードに 1 を書き込み、箱 4 に入れます。
- 箱 4 に入っているカードに書かれた数は 1, 1, 2 です。
- 1 を 2 度出力することに注意してください。
- 数 1 が書かれたカードが入っている箱は箱 1, 4 です。
- 箱 4 には数 1 が書かれたカードが 2 枚入っていますが、4 は 1 回しか出力しないことに注意してください。
- 数 2 が書かれたカードが入っている箱は箱 4 です。
入力例 2
1 5 1 1 1 1 2 1 1 200000 1 2 1 3 200000
出力例 2
1 2 200000 1
Score : 300 points
Problem Statement
We have N boxes numbered 1 to N that are initially empty, and an unlimited number of blank cards.
Process Q queries in order. There are three kinds of queries as follows.
1 i j\colon Write the number i on a blank card and put it into box j.2 i\colon Report all numbers written on the cards in box i, in ascending order.3 i\colon Report all box numbers of the boxes that contain a card with the number i, in ascending order.
Here, note the following.
- In a query of the second kind, if box i contains multiple cards with the same number, that number should be printed the number of times equal to the number of those cards.
- In a query of the third kind, even if a box contains multiple cards with the number i, the box number of that box should be printed only once.
Constraints
- 1 \leq N, Q \leq 2 \times 10^5
- For a query of the first kind:
- 1 \leq i \leq 2 \times 10^5
- 1 \leq j \leq N
- For a query of the second kind:
- 1 \leq i \leq N
- Box i contains some cards when this query is given.
- For a query of the third kind:
- 1 \leq i \leq 2 \times 10^5
- Some boxes contain a card with the number i when this query is given.
- At most 2 \times 10^5 numbers are to be reported.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_q denotes the q-th query, which is in one of the following formats:
1 i j
2 i
3 i
Output
Respond to the queries of the second and third kinds in order.
For each of those queries, print one line containing the elements to be reported in ascending order, with spaces in between.
Sample Input 1
5 8 1 1 1 1 2 4 1 1 4 2 4 1 1 4 2 4 3 1 3 2
Sample Output 1
1 2 1 1 2 1 4 4
Let us process the queries in order.
- Write 1 on a card and put it into box 1.
- Write 2 on a card and put it into box 4.
- Write 1 on a card and put it into box 4.
- Box 4 contains cards with the numbers 1 and 2.
- Print 1 and 2 in this order.
- Write 1 on a card and put it into box 4.
- Box 4 contains cards with the numbers 1, 1, and 2.
- Note that you should print 1 twice.
- Boxes 1 and 4 contain a card with the number 1.
- Note that you should print 4 only once, even though box 4 contains two cards with the number 1.
- Boxes 4 contains a card with the number 2.
Sample Input 2
1 5 1 1 1 1 2 1 1 200000 1 2 1 3 200000
Sample Output 2
1 2 200000 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
1, 2, \ldots, 2N と番号づけられた 2N 人の人が舞踏会に参加します。 彼らは N 個の 2 人組にわかれてダンスを踊ります。
2 人組を構成する人のうち、番号の小さい方の人が人 i 、番号の大きい方の人が人 j のとき、
その 2 人組の「相性」は A_{i, j} です。
N 個の 2 人組の相性がそれぞれ B_1, B_2, \ldots, B_N であるとき、
「舞踏会全体の楽しさ」はそれらのビットごとの排他的論理和である B_1 \oplus B_2 \oplus \cdots \oplus B_N です。
「 2N 人の参加者が N 個の 2 人組に分かれる方法」を自由に選べるとき、「舞踏会全体の楽しさ」としてあり得る最大値を出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq A_{i, j} < 2^{30}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}
出力
舞踏会全体の楽しさとしてあり得る最大値を出力せよ。
入力例 1
2 4 0 1 5 3 2
出力例 1
6
人 i と人 j からなる 2 人組を \lbrace i, j\rbrace で表します。 4 人が 2 個の 2 人組にわかれる方法は下記の 3 通りです。
- \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6 です。
- \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3 です。
- \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace という 2 組にわかれる。 このとき、舞踏会全体の楽しさは A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4 です。
よって、舞踏会全体の楽しさとしてあり得る最大値は 6 です。
入力例 2
1 5
出力例 2
5
人 1 と人 2 からなる 2 人組のみが作られ、このときの舞踏会全体の楽しさは 5 です。
入力例 3
5 900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467 369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136 138172503 571268336 111747377 595746631 934427285 840101927 757856472 655483844 580613112 445614713 607825444 252585196 725229185 827291247 105489451 58628521 1032791417 152042357 919691140 703307785 100772330 370415195 666350287 691977663 987658020 1039679956 218233643 70938785
出力例 3
1073289207
Score : 400 points
Problem Statement
2N people numbered 1, 2, \ldots, 2N attend a ball. They will group into N pairs and have a dance.
If Person i and Person j pair up, where i is smaller than j, the affinity of that pair is A_{i, j}.
If the N pairs have the affinity of B_1, B_2, \ldots, B_N, the total fun of the ball is the bitwise XOR of them: B_1 \oplus B_2 \oplus \cdots \oplus B_N.
Print the maximum possible total fun of the ball when the 2N people can freely group into N pairs.
Constraints
- 1 \leq N \leq 8
- 0 \leq A_{i, j} < 2^{30}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_{1, 2} A_{1, 3} A_{1, 4} \cdots A_{1, 2N}
A_{2, 3} A_{2, 4} \cdots A_{2, 2N}
A_{3, 4} \cdots A_{3, 2N}
\vdots
A_{2N-1, 2N}
Output
Print the maximum possible total fun of the ball.
Sample Input 1
2 4 0 1 5 3 2
Sample Output 1
6
Let \lbrace i, j\rbrace denote a pair of Person i and Person j. There are three ways for the four people to group into two pairs, as follows.
- Group into \lbrace 1, 2\rbrace, \lbrace 3, 4\rbrace. The total fun of the ball here is A_{1, 2} \oplus A_{3, 4} = 4 \oplus 2 = 6.
- Group into \lbrace 1, 3\rbrace, \lbrace 2, 4\rbrace. The total fun of the ball here is A_{1, 3} \oplus A_{2, 4} = 0 \oplus 3 = 3.
- Group into \lbrace 1, 4\rbrace, \lbrace 2, 3\rbrace. The total fun of the ball here is A_{1, 4} \oplus A_{2, 3} = 1 \oplus 5 = 4.
Therefore, the maximum possible total fun of the ball is 6.
Sample Input 2
1 5
Sample Output 2
5
There will be just a pair of Person 1 and Person 2, where the total fun of the ball is 5.
Sample Input 3
5 900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467 369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136 138172503 571268336 111747377 595746631 934427285 840101927 757856472 655483844 580613112 445614713 607825444 252585196 725229185 827291247 105489451 58628521 1032791417 152042357 919691140 703307785 100772330 370415195 666350287 691977663 987658020 1039679956 218233643 70938785
Sample Output 3
1073289207
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
H 行 W 列の格子状の区画に区切られた街があります。上から i 行目、左から j 列目の区画は、S_{i,j} が . のとき道、# のとき塀です。
高橋君は自分の家から魚屋に買い物に行くことにしました。高橋君の家は街の左上隅の区画にあり、魚屋は街の右下隅の区画にあります。
高橋君は、自分がいる区画から上下左右に隣接する道の区画に移動することができます。街の外に出ることはできません。
塀の区画に移動することはできませんが、高橋君は非常に腕力が強いため、パンチを 1 回繰り出すことで任意の 2\times 2 の区画内の塀を壊して道にすることができます。
高橋君が魚屋にたどり着くためには、最低何回パンチを繰り出せばよいか求めてください。
制約
- 2 \leq H,W \leq 500
- H,W は整数
- S_{i,j} は
.または# - S_{1,1} と S_{H,W} は
.
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1} \ldots S_{1,W}
\vdots
S_{H,1} \ldots S_{H,W}
出力
答えを出力せよ。
入力例 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
出力例 1
1
例えば、以下の * で表す 2\times 2 の区画にある塀を破壊すると魚屋にたどり着くことができます。
..#.. #.**# ##**# #.#.# ..#..
破壊対象の 2 \times 2 の区画の全てが塀である必要はありません。
入力例 2
5 7 ....... ######. ....... .###### .......
出力例 2
0
遠回りが必要ですが、塀を破壊することなく魚屋にたどり着くことができます。
入力例 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
出力例 3
5
Score : 500 points
Problem Statement
There is a town divided into a grid of cells with H rows and W columns. The cell at the i-th row from the top and j-th column from the left is a passable space if S_{i,j} is . and a block if S_{i,j} is #.
Takahashi will go from his house to a fish market. His house is in the cell at the top-left corner, and the fish market is in the cell at the bottom-right corner.
Takahashi can move one cell up, down, left, or right to a passable cell. He cannot leave the town. He cannot enter a block, either. However, his physical strength allows him to destroy all blocks in a square region with 2\times 2 cells of his choice with one punch, making these cells passable.
Find the minimum number of punches needed for Takahashi to reach the fish market.
Constraints
- 2 \leq H,W \leq 500
- H and W are integers.
- S_{i,j} is
.or#. - S_{1,1} and S_{H,W} are
..
Input
Input is given from Standard Input in the following format:
H W
S_{1,1} \ldots S_{1,W}
\vdots
S_{H,1} \ldots S_{H,W}
Output
Print the answer.
Sample Input 1
5 5 ..#.. #.#.# ##.## #.#.# ..#..
Sample Output 1
1
He can reach the fish market by, for example, destroying the blocks in the square region with 2\times 2 cells marked * below.
..#.. #.**# ##**# #.#.# ..#..
It is not required that all of the 2\times 2 cells in the region to punch are blocks.
Sample Input 2
5 7 ....... ######. ....... .###### .......
Sample Output 2
0
He can reach the fish market without destroying blocks, though he has to go a long way around.
Sample Input 3
8 8 .####### ######## ######## ######## ######## ######## ######## #######.
Sample Output 3
5
実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
N 個の箱があります。 i 番目の箱は高さ・幅・奥行きがそれぞれ h_i,w_i,d_i の直方体の形をしています。
二つの箱であって、必要ならば回転させることで片方の高さ・幅・奥行きがもう片方の高さ・幅・奥行きをそれぞれ上回るようなものが存在するかを判定してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq h_i,w_i,d_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N h_1 w_1 d_1 \vdots h_N w_N d_N
出力
二つの箱であって、必要ならば回転させることで片方の高さ・幅・奥行きがもう片方の高さ・幅・奥行きをそれぞれ上回るようなものが存在するならば Yes と、そうでなければ No と出力せよ。
入力例 1
3 19 8 22 10 24 12 15 25 11
出力例 1
Yes
2 番目の箱を回転させて高さと奥行きを入れ替えると、3 番目の箱が高さ・幅・奥行きをそれぞれ上回ります。
入力例 2
3 19 8 22 10 25 12 15 24 11
出力例 2
No
入力例 3
2 1 1 2 1 2 2
出力例 3
No
Score : 525 points
Problem Statement
There are N boxes. The i-th box has a shape of a rectangular cuboid whose height, width, and depth are h_i,w_i, and d_i, respectively.
Determine if there are two boxes such that one's height, width, and depth are strictly greater than those of the other after rotating them if necessary.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq h_i,w_i,d_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N h_1 w_1 d_1 \vdots h_N w_N d_N
Output
Print Yes if there are two boxes such that one's height, width, and depth are strictly greater than those of the other after rotating them if necessary; print No otherwise.
Sample Input 1
3 19 8 22 10 24 12 15 25 11
Sample Output 1
Yes
If you rotate the 2-nd box to swap its height and depth, the 3-rd box will have greater height, depth, and width.
Sample Input 2
3 19 8 22 10 25 12 15 24 11
Sample Output 2
No
Sample Input 3
2 1 1 2 1 2 2
Sample Output 3
No