Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1 から 2N の番号がついた 2N 人でじゃんけん大会をします。
大会は M ラウンドからなり、各ラウンドは、全ての人が 1 度ずつ参加するような 1 対 1 の N 試合からなります。
i=0,1,\ldots,M について、i ラウンド目の終了時点での順位を次のように決めます。
- i ラウンド目までの勝数が多い方が上位
- i ラウンド目までの勝数が同じときは、番号が小さい方が上位
また、i=1,\ldots,M について、i ラウンド目の各試合の組み合わせを次のように決めます。
- 各 k=1,2,\ldots,N について、i-1 ラウンド目終了時点の順位が 2k-1 位の人と 2k 位の人が試合をする
各試合では、対戦する 2 人がそれぞれ 1 度だけ手を出し、勝ち・負け・引き分けのいずれかの結果が発生します。
未来予知ができる高橋君は、人 i が j ラウンド目の試合で出す手が A_{i,j} であることを知っています。
A_{i,j} は G, C, P のいずれかであり、それぞれグー、チョキ、パーを表します。
M ラウンド目終了時点の順位を求めてください。
じゃんけんのルール
じゃんけんの結果は、2 人の出した手に応じて次のように決まります。- 一方がグーで他方がチョキのとき、グーを出した人が勝ち、チョキを出した人は負け
- 一方がチョキで他方がパーのとき、チョキを出した人が勝ち、パーを出した人は負け
- 一方がパーで他方がグーのとき、パーを出した人が勝ち、グーを出した人は負け
- 両者が同じ手を出したとき、引き分け
制約
- 1 \leq N \leq 50
- 1 \leq M \leq 100
- A_{i,j} は
G,C,Pのいずれか
入力
入力は以下の形式で標準入力から与えられる。
N M
A_{1,1}A_{1,2}\ldots A_{1,M}
A_{2,1}A_{2,2}\ldots A_{2,M}
\vdots
A_{2N,1}A_{2N,2}\ldots A_{2N,M}
出力
2N 行出力せよ。
i 行目には、M ラウンド目終了時点での順位が i 位である人の番号を出力せよ。
入力例 1
2 3 GCP PPP CCC PPC
出力例 1
3 1 2 4
1 ラウンド目では人 1 と 2、3 と 4 がそれぞれ試合をし、前者の試合は人 2 が、後者の試合は人 3 が勝ちます。
2 ラウンド目では人 2 と 3、1 と 4 がそれぞれ試合をし、前者の試合は人 3 が、後者の試合は人 1 が勝ちます。
3 ラウンド目では人 3 と 1、2 と 4 がそれぞれ試合をし、前者の試合は人 3 が、後者の試合は人 4 が勝ちます。
よって最終的な順位は、上位から順に人 3,1,2,4 となります。
入力例 2
2 2 GC PG CG PP
出力例 2
1 2 3 4
1 ラウンド目では人 1 と 2、3 と 4 がそれぞれ試合をし、前者の試合は人 2 が、後者の試合は人 3 が勝ちます。
2 ラウンド目では人 2 と 3、1 と 4 がそれぞれ試合をし、前者の試合は引き分け、後者の試合は人 1 が勝ちます。
よって最終的な順位は、上位から順に人 1,2,3,4 となります。
Score : 300 points
Problem Statement
2N players, with ID numbers 1 through 2N, will participate in a rock-scissors-paper contest.
The contest has M rounds. Each round has N one-on-one matches, where each player plays in one of them.
For each i=0, 1, \ldots, M, the players' ranks at the end of the i-th round are determined as follows.
- A player with more wins in the first i rounds ranks higher.
- Ties are broken by ID numbers: a player with a smaller ID number ranks higher.
Additionally, for each i=1, \ldots, M, the matches in the i-th round are arranged as follows.
- For each k=1, 2, \ldots, N, a match is played between the players who rank (2k-1)-th and 2k-th at the end of the (i-1)-th round.
In each match, the two players play a hand just once, resulting in one player's win and the other's loss, or a draw.
Takahashi, who can foresee the future, knows that Player i will play A_{i, j} in their match in the j-th round, where A_{i,j} is G, C, or P.
Here, G stands for rock, C stands for scissors, and P stands for paper. (These derive from Japanese.)
Find the players' ranks at the end of the M-th round.
Rules of rock-scissors-paper
The result of a rock-scissors-paper match is determined as follows, based on the hands played by the two players.- If one player plays rock (G) and the other plays scissors (C), the player playing rock (G) wins.
- If one player plays scissors (C) and the other plays paper (P), the player playing scissors (C) wins.
- If one player plays paper (P) and the other plays rock (G), the player playing paper (P) wins.
- If the players play the same hand, the match is drawn.
Constraints
- 1 \leq N \leq 50
- 1 \leq M \leq 100
- A_{i,j} is
G,C, orP.
Input
Input is given from Standard Input in the following format:
N M
A_{1,1}A_{1,2}\ldots A_{1,M}
A_{2,1}A_{2,2}\ldots A_{2,M}
\vdots
A_{2N,1}A_{2N,2}\ldots A_{2N,M}
Output
Print 2N lines.
The i-th line should contain the ID number of the player who ranks i-th at the end of the M-th round.
Sample Input 1
2 3 GCP PPP CCC PPC
Sample Output 1
3 1 2 4
In the first round, matches are played between Players 1 and 2, and between Players 3 and 4. Player 2 wins the former, and Player 3 wins the latter.
In the second round, matches are played between Players 2 and 3, and between Players 1 and 4. Player 3 wins the former, and Player 1 wins the latter.
In the third round, matches are played between Players 3 and 1, and between Players 2 and 4. Player 3 wins the former, and Player 4 wins the latter.
Therefore, in the end, the players are ranked in the following order: 3,1,2,4, from highest to lowest.
Sample Input 2
2 2 GC PG CG PP
Sample Output 2
1 2 3 4
In the first round, matches are played between Players 1 and 2, and between Players 3 and 4. Player 2 wins the former, and Player 3 wins the latter.
In the second round, matches are played between Players 2 and 3, and between Players 1 and 4. The former is drawn, and Player 1 wins the latter.
Therefore, in the end, the players are ranked in the following order: 1,2,3,4, from highest to lowest.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 鉄道のとある路線には N 個の駅が存在し、始点から終点に向かって i \, (1 \leq i \leq N) 番目の駅の名前は S_i です。
普通列車は全ての駅に止まりますが、急行列車は全ての駅に止まるとは限りません。具体的には、急行列車は M \, (M \leq N) 個の駅にのみ止まり、j \, (1 \leq j \leq M) 番目に止まる駅の名前は T_j です。
ただし、T_1 = S_1 かつ T_M = S_N、すなわち急行列車は始点と終点の両方に止まることが保証されます。
N 個の駅それぞれについて、その駅に急行列車が止まるかどうか判定してください。
制約
- 2 \leq M \leq N \leq 10^5
- N, M は整数
- S_i \, (1 \leq i \leq N) は英小文字のみからなる 1 文字以上 10 文字以下の文字列
- S_i \neq S_j \, (i \neq j)
- T_1 = S_1 かつ T_M = S_N
- (T_1, \dots, T_M) は (S_1, \dots, S_N) から 0 個以上の文字列を選んで取り除き、残った文字列を元の順序で並べることで得られる
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 \ldots S_N T_1 \ldots T_M
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、始点から終点に向かって i 番目の駅に急行列車が止まるなら Yes、そうでないなら No と出力せよ。
入力例 1
5 3 tokyo kanda akiba okachi ueno tokyo akiba ueno
出力例 1
Yes No Yes No Yes
入力例 2
7 7 a t c o d e r a t c o d e r
出力例 2
Yes Yes Yes Yes Yes Yes Yes
急行列車が全ての駅に止まることもあります。
Score : 300 points
Problem Statement
There are N stations on a certain line operated by AtCoder Railway. The i-th station (1 \leq i \leq N) from the starting station is named S_i.
Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only M \, (M \leq N) stations, and the j-th stop (1 \leq j \leq M) is the station named T_j.
Here, it is guaranteed that T_1 = S_1 and T_M = S_N, that is, express trains stop at both starting and terminal stations.
For each of the N stations, determine whether express trains stop at that station.
Constrains
- 2 \leq M \leq N \leq 10^5
- N and M are integers.
- S_i (1 \leq i \leq N) is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
- S_i \neq S_j \, (i \neq j)
- T_1 = S_1 and T_M = S_N.
- (T_1, \dots, T_M) is obtained by removing zero or more strings from (S_1, \dots, S_N) and lining up the remaining strings without changing the order.
Input
Input is given from Standard Input in the following format:
N M S_1 \ldots S_N T_1 \ldots T_M
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain Yes if express trains stop at the i-th station from the starting station, and No otherwise.
Sample Input 1
5 3 tokyo kanda akiba okachi ueno tokyo akiba ueno
Sample Output 1
Yes No Yes No Yes
Sample Input 2
7 7 a t c o d e r a t c o d e r
Sample Output 2
Yes Yes Yes Yes Yes Yes Yes
Express trains may stop at all stations.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は N 種類の硬貨をそれぞれ何枚か持っており、 具体的には、1\leq i\leq N について A_i 円硬貨を B_i 枚持っています。
高橋君が現在持っている硬貨を用いて、(お釣りが出ないように)ちょうど X 円を支払うことができるか判定してください。
制約
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
高橋君が現在持っている硬貨を用いてちょうど X 円を支払うことができる場合は Yes を、
できない場合は No を出力せよ。
入力例 1
2 19 2 3 5 6
出力例 1
Yes
高橋君は 2 円硬貨を 3 枚、5 円硬貨を 6 枚持っています。
このうち、2 円硬貨を 2 枚、5 円硬貨を 3 枚用いることでちょうど 2\times 2+5\times 3=19 円を支払うことができます。
よって、Yes を出力します。
入力例 2
2 18 2 3 5 6
出力例 2
No
持っている硬貨をどのように組み合わせてもちょうど 18 円を支払うことはできません。
よって、No を出力します。
入力例 3
3 1001 1 1 2 1 100 10
出力例 3
Yes
1 枚も使用しない硬貨が存在しても構いません。
Score : 400 points
Problem Statement
Takahashi has N kinds of coins; specifically, for 1\leq i\leq N, he has B_i coins worth A_i yen (the currency in Japan) each.
Determine if Takahashi can pay exactly X yen (without change) with the coins he currently has.
Constraints
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i are pairwise distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print Yes if Takahashi can pay exactly X yen with the coins he currently has;
print No otherwise.
Sample Input 1
2 19 2 3 5 6
Sample Output 1
Yes
Takahashi has three 2-yen coins and six 5-yen coins.
He can use two 2-yen coins and three 5-yen coins to pay exactly 2\times 2+5\times 3=19 yen.
Thus, Yes should be printed.
Sample Input 2
2 18 2 3 5 6
Sample Output 2
No
There is no combination of the coins that he can use to pay exactly 18 yen.
Thus, No should be printed.
Sample Input 3
3 1001 1 1 2 1 100 10
Sample Output 3
Yes
He need not use all kinds of coins.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
正の整数 N が与えられます。 \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right] の値を求めてください。
ただし、実数 x に対して [x] で x 以下の最大の整数を表します。
制約
- 1 \leq N \leq 10^{12}
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
5
\left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5 です。
入力例 2
10000000000
出力例 2
231802823220
入力や出力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 500 points
Problem Statement
Given is a positive integer N. Find the value \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right].
Here, for a real number x, [x] denotes the largest integer not exceeding x.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
5
We have \left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5.
Sample Input 2
10000000000
Sample Output 2
231802823220
Note that the input and output may not fit into a 32-bit integer type.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
以下のいずれかの条件を満たす文字列を正しい括弧列と定義します。
- 空文字列
- ある正しい括弧列 A が存在して、
(, A,)をこの順に連結した文字列 - ある空でない正しい括弧列 A, B が存在して、A, B をこの順に連結した文字列
( と ) のみからなる長さ N の文字列 S があります。
Q 個のクエリ \text{Query}_1,\text{Query}_2,\ldots,\text{Query}_Q が与えられるので、順番に処理してください。クエリには 2 種類があり、入力形式とクエリの内容は以下の通りです。
1 l r: S の l 文字目と r 文字目を入れ替える。2 l r: S の l 文字目から r 文字目までの連続部分文字列が正しい括弧列であるか判定する。
制約
- 1 \leq N,Q \leq 2 \times 10^5
- S は
(と)のみからなる長さ N の文字列 - 1 \leq l < r \leq N
- N,Q,l,r はいずれも整数
- 各クエリは
1 l r、2 l rのいずれかの形式で与えられる。 2 l rの形式のクエリは 1 つ以上与えられる。
入力
入力は以下の形式で標準入力から与えられる。
N Q
S
\text{Query}_1
\text{Query}_2
\vdots
\text{Query}_Q
出力
2 l r の形式の各クエリに対して、連続部分文字列が正しい括弧列である場合 Yes、そうでない場合 No と出力し、改行せよ。
入力例 1
5 3 (())( 2 1 4 2 1 2 2 4 5
出力例 1
Yes No No
1 つ目のクエリにおいて、(()) は正しい括弧列です。
2 つ目のクエリにおいて、(( は正しい括弧列ではありません。
3 つ目のクエリにおいて、)( は正しい括弧列ではありません。
入力例 2
5 3 (())( 2 1 4 1 1 4 2 1 4
出力例 2
Yes No
1 つ目のクエリにおいて、(()) は正しい括弧列です。
2 つ目のクエリによって、S は )()(( となります。
3 つ目のクエリにおいて、)()( は正しい括弧列ではありません。
入力例 3
8 8 (()(())) 2 2 7 2 2 8 1 2 5 2 3 4 1 3 4 1 3 5 1 1 4 1 6 8
出力例 3
Yes No No
Score : 500 points
Problem Statement
Let us define a correct parenthesis sequence as a string that satisfies one of the following conditions.
- It is an empty string.
- It is a concatenation of
(, A,), in this order, for some correct parenthesis sequence A. - It is a concatenation of A, B, in this order, for some correct parenthesis sequences A and B.
We have a string S of length N consisting of ( and ).
Given Q queries \text{Query}_1,\text{Query}_2,\ldots,\text{Query}_Q, process them in order. There are two kinds of queries, with the following formats and content.
1 l r: Swap the l-th and r-th characters of S.2 l r: Determine whether the contiguous substring from the l-th through the r-th character is a correct parenthesis sequence.
Constraints
- 1 \leq N,Q \leq 2 \times 10^5
- S is a string of length N consisting of
(and). - 1 \leq l < r \leq N
- N,Q,l,r are all integers.
- Each query is in the format
1 l ror2 l r. - There is at least one query in the format
2 l r.
Input
Input is given from Standard Input in the following format:
N Q
S
\text{Query}_1
\text{Query}_2
\vdots
\text{Query}_Q
Output
For each query in the format 2 l r, print Yes if the contiguous substring is a correct parenthesis sequence, and No otherwise, followed by a newline.
Sample Input 1
5 3 (())( 2 1 4 2 1 2 2 4 5
Sample Output 1
Yes No No
In the first query, (()) is a correct parenthesis sequence.
In the second query, (( is not a correct parenthesis sequence.
In the third query, )( is not a correct parenthesis sequence.
Sample Input 2
5 3 (())( 2 1 4 1 1 4 2 1 4
Sample Output 2
Yes No
In the first query, (()) is a correct parenthesis sequence.
In the second query, S becomes )()((.
In the third query, )()( is not a correct parenthesis sequence.
Sample Input 3
8 8 (()(())) 2 2 7 2 2 8 1 2 5 2 3 4 1 3 4 1 3 5 1 1 4 1 6 8
Sample Output 3
Yes No No