Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は置き時計を買いました。
この時計は、現在の時刻が 24 時制で \mathrm{AB} 時 \mathrm{CD} 分であるときに図 1 のように時刻を表します。
例えば図 2 では、時計は 7 時 58 分を示しています。
時刻の表示方法をより形式的に説明すると次のようになります。
現在の時刻が 24 時制で h 時 m 分であるとします。ここで 24 時制とは、時間を 0 以上 23 以下の整数で、分を 0 以上 59 以下の整数で表す時刻の表現方法を言います。
h の 10 の位を A, 1 の位を B, m の 10 の位を C, 1 の位を D とします。(ただし h, m が 1 桁である場合は先行ゼロを追加して考えます。)
このとき時計は左上に A を、左下に B を、右上に C を、右下に D を表示します。
高橋君は、次の条件を満たす時刻を 見間違えやすい時刻 と呼ぶことにしました。
- 時計の表示の右上と左下を入れ替えても、それに対応する 24 時制の時刻が存在する。
例えば 図 3 は 20 時 13 分を示していますが、時計の表示の右上と左下を入れ替えると 21 時 3 分を意味する表示になります。よって 20 時 13 分は見間違えやすい時刻です。
今、時計は H 時 M 分を示しています。
(現時点も含めて)以降はじめて訪れる見間違えやすい時刻を 24 時制で答えてください。
制約
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H, M は整数
入力
入力は以下の形式で標準入力から与えられる。
H M
出力
答えを h 時 m 分とする。ここで h, m は 0 \leq h \leq 23, 0 \leq m \leq 59 である必要がある。
このとき h, m を以下の形式で出力せよ。
h m
なお、h, m を 2 桁に揃えるために先行ゼロをつけた形式で出力しても正答と見なされる。
入力例 1
1 23
出力例 1
1 23
1 時 23 分は見間違えやすい時刻です。なぜならば、時計の表示の右上と左下を入れ替えると 2 時 13 分を意味する表示になるからです。
よって答えは 1 時 23 分です。
なお、01 23
のように先行ゼロをつけた形式で出力しても正答として扱われます。
入力例 2
19 57
出力例 2
20 0
19 時 57 分以降ではじめて訪れる見間違えやすい時刻は 20 時 0 分です。
入力例 3
20 40
出力例 3
21 0
24 時制では 24 時 0 分という表記は合法でないのに注意してください。
Score : 200 points
Problem Statement
Takahashi bought a table clock.
The clock shows the time as shown in Figure 1 at \mathrm{AB}:\mathrm{CD} in the 24-hour system.
For example, the clock in Figure 2 shows 7:58.
The format of the time is formally described as follows.
Suppose that the current time is m minutes past h in the 24-hour system. Here, the 24-hour system represents the hour by an integer between 0 and 23 (inclusive), and the minute by an integer between 0 and 59 (inclusive).
Let A be the tens digit of h, B be the ones digit of h, C be the tens digit of m, and D be the ones digit of m. (Here, if h has only one digit, we consider that it has a leading zero; the same applies to m.)
Then, the clock shows A in its top-left, B in its bottom-left, C in its top-right, and D in its bottom-right.
Takahashi has decided to call a time a confusing time if it satisfies the following condition:
- after swapping the top-right and bottom-left digits on the clock, it still reads a valid time in the 24-hour system.
For example, the clock in Figure 3 shows 20:13. After swapping its top-right and bottom-left digits, it reads 21:03. Thus, 20:13 is a confusing time.
The clock now shows H:M.
Find the next confusing time (including now) in the 24-hour system.
Constraints
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H and M are integers.
Input
The input is given from Standard Input in the following format:
H M
Output
Let h:m be the answer, where h and m must satisfy 0 \leq h \leq 23 and 0 \leq m \leq 59.
Print h and m in the following format:
h m
Your answer is considered correct even if h contains a leading zero to represent it as a 2-digit integer; the same applies to m.
Sample Input 1
1 23
Sample Output 1
1 23
1:23 is a confusing time because, after swapping its top-right and bottom-left digits on the clock, it reads 2:13.
Thus, the answer is 1:23.
Your answer is considered correct even if you print 01 23
with a leading zero.
Sample Input 2
19 57
Sample Output 2
20 0
The next confusing time after 19:57 is 20:00.
Sample Input 3
20 40
Sample Output 3
21 0
Note that 24:00 is an invalid notation in the 24-hour system.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
子供と大人があわせて N 人います。i 番目の人の体重は W_i です。
それぞれの人が子供か大人かは、0
と 1
からなる長さ N の文字列 S によって表され、
S の i 文字目が 0
であるとき i 番目の人が子供であることを、1
であるとき i 番目の人が大人であることをさします。
ロボットである高橋君に対して実数 X を設定すると、
高橋君はそれぞれの人に対して、体重が X 未満なら子供、X 以上なら大人と判定します。
実数 X に対してf(X) を、高橋君に X を設定したときに N 人のうち子供か大人かを正しく判定できる人数で定めます。
X が実数全体を動くとき、f(X) の最大値を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- S は
0
と1
からなる長さ N の文字列 - 1\leq W_i\leq 10^9
- N,W_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N S W_1 W_2 \ldots W_N
出力
f(X) の最大値を整数で一行に出力せよ。
入力例 1
5 10101 60 45 30 40 80
出力例 1
4
X=50 と設定すると、高橋君は 2,3,4 番目の人を子供、 1,5 番目の人を大人と判定します。
実際には 2,4 番目の人が子供、 1,3,5 番目の人が大人であるので、このとき、1,2,4,5 番目の合計 4 人に対して正しく判定できています。
よって、f(50)=4 です。
5 人全員に対して正しく判定できるような X は存在しないのでこのときが最大です。よって、4 を出力します。
入力例 2
3 000 1 2 3
出力例 2
3
例えば、X=10 とすると最大値 f(10)=3 を達成します。
全員が大人、または全員が子供である可能性もあることに注意してください。
入力例 3
5 10101 60 50 50 50 60
出力例 3
4
例えば、X=55 とすると最大値 f(55)=4 を達成します。
同じ体重の人が複数人存在する可能性もあることに注意してください。
Score : 300 points
Problem Statement
There are N people, each of whom is either a child or an adult. The i-th person has a weight of W_i.
Whether each person is a child or an adult is specified by a string S of length N consisting of 0
and 1
.
If the i-th character of S is 0
, then the i-th person is a child; if it is 1
, then the i-th person is an adult.
When Takahashi the robot is given a real number X,
Takahashi judges a person with a weight less than X to be a child and a person with a weight more than or equal to X to be an adult.
For a real value X, let f(X) be the number of people whom Takahashi correctly judges whether they are children or adults.
Find the maximum value of f(X) for all real values of X.
Constraints
- 1\leq N\leq 2\times 10^5
- S is a string of length N consisting of
0
and1
. - 1\leq W_i\leq 10^9
- N and W_i are integers.
Input
Input is given from Standard Input in the following format:
N S W_1 W_2 \ldots W_N
Output
Print the maximum value of f(X) as an integer in a single line.
Sample Input 1
5 10101 60 45 30 40 80
Sample Output 1
4
When Takahashi is given X=50, it judges the 2-nd, 3-rd, and 4-th people to be children and the 1-st and 5-th to be adults.
In reality, the 2-nd and 4-th are children, and the 1-st, 3-rd, and 5-th are adults, so the 1-st, 2-nd, 4-th, and 5-th people are correctly judged.
Thus, f(50)=4.
This is the maximum since there is no X that judges correctly for all 5 people. Thus, 4 should be printed.
Sample Input 2
3 000 1 2 3
Sample Output 2
3
For example, X=10 achieves the maximum value f(10)=3.
Note that the people may be all children or all adults.
Sample Input 3
5 10101 60 50 50 50 60
Sample Output 3
4
For example, X=55 achieves the maximum value f(55)=4.
Note that there may be multiple people with the same weight.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 x,y に対して f(x,y) を「(x+y) を 10^8 で割ったあまり」として定義します。
長さ N の正整数列 A=(A_1,\ldots,A_N) が与えられます。次の式の値を求めてください。
制約
- 2\leq N\leq 3\times 10^5
- 1\leq A_i < 10^8
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 3 50000001 50000002
出力例 1
100000012
- f(A_1,A_2)=50000004
- f(A_1,A_3)=50000005
- f(A_2,A_3)=3
なので、答えは f(A_1,A_2)+f(A_1,A_3)+f(A_2,A_3) = 100000012 です。
総和を 10^8 で割ったあまりを求めるわけではないことに注意してください。
入力例 2
5 1 3 99999999 99999994 1000000
出力例 2
303999988
Score: 300 points
Problem Statement
For positive integers x and y, define f(x, y) as the remainder of (x + y) divided by 10^8.
You are given a sequence of positive integers A = (A_1, \ldots, A_N) of length N. Find the value of the following expression:
Constraints
- 2 \leq N \leq 3\times 10^5
- 1 \leq A_i < 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
3 3 50000001 50000002
Sample Output 1
100000012
- f(A_1,A_2)=50000004
- f(A_1,A_3)=50000005
- f(A_2,A_3)=3
Thus, the answer is f(A_1,A_2) + f(A_1,A_3) + f(A_2,A_3) = 100000012.
Note that you are not asked to compute the remainder of the sum divided by 10^8.
Sample Input 2
5 1 3 99999999 99999994 1000000
Sample Output 2
303999988
Time Limit: 2 sec / Memory Limit: 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