実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 233 点
問題文
高橋君の部屋には N 個の照明があります。それぞれの照明には、ON/OFF を切り替えるスイッチが 1 つずつ付いています。スイッチを 1 回押すたびに、その照明の状態が反転します(ON なら OFF に、OFF なら ON になります)。各照明のスイッチはその照明のみに影響し、他の照明の状態は変化しません。
各照明の初期状態(ON または OFF)は文字列 S_i で与えられます。S_i が Yes のとき照明 i の初期状態は ON を、No のとき初期状態は OFF を表します。
高橋君はこれから、各照明 i(1 \leq i \leq N)について、i 番目の照明のスイッチをちょうど K_i 回押します。
すべてのスイッチ操作を終えた後の、各照明の最終的な状態を求めてください。
制約
- 1 \leq N \leq 10^5
- S_i は
YesまたはNoのいずれかである - 1 \leq K_i \leq 10^9
- N, K_i はすべて整数である
入力
N S_1 K_1 S_2 K_2 \vdots S_N K_N
- 1 行目には、照明の数を表す整数 N が与えられる。
- 続く N 行のうち i 行目には、i 番目の照明の初期状態を表す文字列 S_i と、スイッチを押す回数を表す整数 K_i が、スペース区切りで与えられる。
出力
N 行出力せよ。i 行目には、i 番目の照明の最終的な状態が ON であれば Yes を、OFF であれば No を出力せよ。
入力例 1
3 Yes 1 No 2 Yes 3
出力例 1
No No No
入力例 2
4 Yes 2 No 1 No 4 Yes 5
出力例 2
Yes Yes No No
入力例 3
6 Yes 100 No 99 Yes 1000000 No 999999 Yes 42 No 7
出力例 3
Yes Yes Yes Yes Yes Yes
入力例 4
10 Yes 1000000000 No 1000000000 Yes 999999999 No 999999999 Yes 1 No 1 Yes 2 No 2 Yes 500000000 No 500000001
出力例 4
Yes No No Yes No Yes Yes No Yes Yes
入力例 5
1 No 1
出力例 5
Yes
Score : 233 pts
Problem Statement
There are N lights in Takahashi's room. Each light has a single switch that toggles it ON/OFF. Each time a switch is pressed, the state of that light is flipped (ON becomes OFF, and OFF becomes ON). Each light's switch only affects that light and does not change the state of any other light.
The initial state (ON or OFF) of each light is given by a string S_i. When S_i is Yes, the initial state of light i is ON, and when S_i is No, the initial state is OFF.
Takahashi will now press the switch of light i exactly K_i times for each light i (1 \leq i \leq N).
Determine the final state of each light after all switch operations are completed.
Constraints
- 1 \leq N \leq 10^5
- S_i is either
YesorNo - 1 \leq K_i \leq 10^9
- N, K_i are all integers
Input
N S_1 K_1 S_2 K_2 \vdots S_N K_N
- The first line contains an integer N representing the number of lights.
- In the following N lines, the i-th line contains a string S_i representing the initial state of the i-th light and an integer K_i representing the number of times the switch is pressed, separated by a space.
Output
Output N lines. On the i-th line, output Yes if the final state of the i-th light is ON, or No if it is OFF.
Sample Input 1
3 Yes 1 No 2 Yes 3
Sample Output 1
No No No
Sample Input 2
4 Yes 2 No 1 No 4 Yes 5
Sample Output 2
Yes Yes No No
Sample Input 3
6 Yes 100 No 99 Yes 1000000 No 999999 Yes 42 No 7
Sample Output 3
Yes Yes Yes Yes Yes Yes
Sample Input 4
10 Yes 1000000000 No 1000000000 Yes 999999999 No 999999999 Yes 1 No 1 Yes 2 No 2 Yes 500000000 No 500000001
Sample Output 4
Yes No No Yes No Yes Yes No Yes Yes
Sample Input 5
1 No 1
Sample Output 5
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君は、N 枚のタイルが一列に並んだ長い廊下を通り抜けようとしています。タイルは左から順にタイル 1, タイル 2, \ldots, タイル N と番号が付けられています。
各タイルにはほこりが積もっており、タイル i には初め H_i の厚さのほこりが積もっています。高橋君がタイル i を踏むと、そのタイルのほこりの厚さは \max(0,\; H_i - D_i) になります。ここで D_i はタイル i に対して定められた非負整数です。高橋君が踏まなかったタイルのほこりの厚さは初期の厚さ H_i のまま変化しません。
高橋君はタイル 1 からスタートし、タイル N がゴールです。高橋君は常に右方向にのみ進みます。具体的には、現在タイル j にいるとき、次の移動先としてタイル j+1 またはタイル j+2 を選べます。ただし、タイル N を超える位置には移動できません(j+1 \leq N のときのみタイル j+1 に、j+2 \leq N のときのみタイル j+2 に移動できます)。高橋君は移動先のタイルに到着した時点でそのタイルを踏みます。スタート地点であるタイル 1 も踏みます。高橋君はタイル N に到達した時点で移動を終了します。
以上の移動ルールにより、タイル 1 とタイル N は必ず踏まれます。また、高橋君は常に右方向に進むため、同じタイルを 2 回以上踏むことはありません。
高橋君が廊下を通り抜けた後、青木君が廊下を調べ、足跡が残っているタイルの数を数えます。タイル i に足跡が残っているとは、高橋君の移動終了後のタイル i のほこりの厚さが初期の厚さ H_i より真に小さくなっていることを意味します。
- 高橋君がタイル i を踏まなかった場合、ほこりの厚さは H_i のままなので、足跡は残りません。
- 高橋君がタイル i を踏んだ場合、ほこりの厚さは \max(0,\; H_i - D_i) になります。これが H_i より真に小さいのは、H_i > 0 かつ D_i > 0 のときに限ります。したがって、H_i = 0 または D_i = 0 ならば踏んでも足跡は残りません。
高橋君は、足跡が残るタイルの数をできるだけ少なくしたいと考えています。高橋君が最適な経路で移動したとき、足跡が残るタイルの数の最小値を求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq H_i \leq 10^9
- 0 \leq D_i \leq 10^9
- 入力はすべて整数である。
入力
N H_1 H_2 \cdots H_N D_1 D_2 \cdots D_N
- 1 行目には、タイルの枚数を表す整数 N が与えられる。
- 2 行目には、各タイルの初期のほこりの厚さを表す N 個の整数 H_1, H_2, \ldots, H_N がスペース区切りで与えられる。
- 3 行目には、各タイルを踏んだときのほこりの減少量の上限を表す N 個の整数 D_1, D_2, \ldots, D_N がスペース区切りで与えられる。
出力
高橋君が最適に移動したとき、足跡が残るタイルの数の最小値を 1 行で出力せよ。
入力例 1
5 3 0 5 2 4 1 1 1 1 1
出力例 1
3
入力例 2
8 5 0 3 0 7 0 2 4 2 3 0 1 1 5 1 3
出力例 2
2
入力例 3
15 1 1 0 1 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
出力例 3
5
Score : 333 pts
Problem Statement
Takahashi is trying to walk through a long corridor consisting of N tiles arranged in a row. The tiles are numbered from left to right as Tile 1, Tile 2, \ldots, Tile N.
Each tile is covered with dust. Initially, Tile i has dust of thickness H_i. When Takahashi steps on Tile i, the dust thickness on that tile becomes \max(0,\; H_i - D_i), where D_i is a non-negative integer defined for Tile i. The dust thickness on tiles that Takahashi does not step on remains unchanged at the initial thickness H_i.
Takahashi starts at Tile 1, and Tile N is the goal. Takahashi always moves only to the right. Specifically, when he is currently on Tile j, he can choose Tile j+1 or Tile j+2 as his next destination. However, he cannot move beyond Tile N (he can move to Tile j+1 only if j+1 \leq N, and to Tile j+2 only if j+2 \leq N). Takahashi steps on a tile upon arriving at it. He also steps on Tile 1, the starting point. Takahashi ends his movement upon reaching Tile N.
Due to the above movement rules, Tile 1 and Tile N are always stepped on. Also, since Takahashi always moves to the right, he never steps on the same tile more than once.
After Takahashi walks through the corridor, Aoki inspects the corridor and counts the number of tiles with footprints. A footprint is left on Tile i if the dust thickness on Tile i after Takahashi's movement is strictly less than the initial thickness H_i.
- If Takahashi did not step on Tile i, the dust thickness remains H_i, so no footprint is left.
- If Takahashi stepped on Tile i, the dust thickness becomes \max(0,\; H_i - D_i). This is strictly less than H_i if and only if H_i > 0 and D_i > 0. Therefore, if H_i = 0 or D_i = 0, no footprint is left even if the tile is stepped on.
Takahashi wants to minimize the number of tiles with footprints. Find the minimum number of tiles with footprints when Takahashi moves along an optimal path.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq H_i \leq 10^9
- 0 \leq D_i \leq 10^9
- All input values are integers.
Input
N H_1 H_2 \cdots H_N D_1 D_2 \cdots D_N
- The first line contains an integer N, the number of tiles.
- The second line contains N integers H_1, H_2, \ldots, H_N separated by spaces, representing the initial dust thickness of each tile.
- The third line contains N integers D_1, D_2, \ldots, D_N separated by spaces, representing the upper bound of dust reduction when each tile is stepped on.
Output
Print in one line the minimum number of tiles with footprints when Takahashi moves optimally.
Sample Input 1
5 3 0 5 2 4 1 1 1 1 1
Sample Output 1
3
Sample Input 2
8 5 0 3 0 7 0 2 4 2 3 0 1 1 5 1 3
Sample Output 2
2
Sample Input 3
15 1 1 0 1 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は街の管理者です。大通りには N 本の街灯が一列に並んでおり、左から順に街灯 1, 街灯 2, \ldots, 街灯 N と番号が付けられています。街灯 i (1 \leq i \leq N) の初期耐久値は H_i です。耐久値が 0 以下になった街灯は倒壊したものとみなされます。
この冬、M 回の吹雪がやってきます。j 回目 (1 \leq j \leq M) の吹雪は、街灯 L_j から街灯 R_j までの範囲に含まれるすべての街灯の耐久値を D_j だけ減少させます。
各街灯の最終的な耐久値は、初期耐久値からすべての吹雪で受けた減少量の合計を引いた値となります。すなわち、途中で耐久値が 0 以下になったとしても、その後の吹雪による減少が免除されることはありません。
すべての吹雪が過ぎ去った後、最終的な耐久値が 1 以上である(すなわち倒壊していない)街灯の本数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
- 1 \leq D_j \leq 10^9 (1 \leq j \leq M)
- 入力はすべて整数である。
入力
N M H_1 H_2 \ldots H_N L_1 R_1 D_1 L_2 R_2 D_2 \vdots L_M R_M D_M
- 1 行目には、街灯の本数 N と吹雪の回数 M が、スペース区切りで与えられる。
- 2 行目には、各街灯の初期耐久値 H_1, H_2, \ldots, H_N が、スペース区切りで与えられる。
- 続く M 行にわたって、各吹雪の情報が与えられる。j 行目には、j 回目の吹雪が影響を及ぼす範囲の左端 L_j、右端 R_j、および耐久値の減少量 D_j がスペース区切りで与えられる。
出力
すべての吹雪が過ぎ去った後、最終的な耐久値が 1 以上である街灯の本数を 1 行で出力せよ。
入力例 1
5 2 10 5 8 3 7 2 4 3 1 3 4
出力例 1
3
入力例 2
3 2 3 2 1 1 3 2 1 1 1
出力例 2
0
入力例 3
10 5 100 50 30 80 60 40 90 20 70 10 1 5 20 3 8 15 6 10 25 1 10 10 2 4 30
出力例 3
5
入力例 4
15 6 1000000000 500 300 800 600 400 900 200 700 100 550 350 750 450 1000000000 1 15 100 1 8 200 5 12 150 3 10 50 7 15 100 1 15 50
出力例 4
10
入力例 5
1 1 1 1 1 1
出力例 5
0
Score : 366 pts
Problem Statement
Takahashi is the manager of a city. Along the main street, N street lights are lined up in a row, numbered from left to right as street light 1, street light 2, \ldots, street light N. The initial durability of street light i (1 \leq i \leq N) is H_i. A street light whose durability becomes 0 or less is considered to have collapsed.
This winter, M blizzards will come. The j-th blizzard (1 \leq j \leq M) decreases the durability of all street lights in the range from street light L_j to street light R_j by D_j.
The final durability of each street light is its initial durability minus the total decrease from all blizzards. That is, even if a street light's durability becomes 0 or less partway through, it is not exempt from the decreases caused by subsequent blizzards.
After all blizzards have passed, determine the number of street lights whose final durability is 1 or more (i.e., that have not collapsed).
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
- 1 \leq D_j \leq 10^9 (1 \leq j \leq M)
- All input values are integers.
Input
N M H_1 H_2 \ldots H_N L_1 R_1 D_1 L_2 R_2 D_2 \vdots L_M R_M D_M
- The first line contains the number of street lights N and the number of blizzards M, separated by a space.
- The second line contains the initial durabilities H_1, H_2, \ldots, H_N of each street light, separated by spaces.
- The following M lines provide information about each blizzard. The j-th line contains the left endpoint L_j, right endpoint R_j of the range affected by the j-th blizzard, and the durability decrease D_j, separated by spaces.
Output
Print in one line the number of street lights whose final durability is 1 or more after all blizzards have passed.
Sample Input 1
5 2 10 5 8 3 7 2 4 3 1 3 4
Sample Output 1
3
Sample Input 2
3 2 3 2 1 1 3 2 1 1 1
Sample Output 2
0
Sample Input 3
10 5 100 50 30 80 60 40 90 20 70 10 1 5 20 3 8 15 6 10 25 1 10 10 2 4 30
Sample Output 3
5
Sample Input 4
15 6 1000000000 500 300 800 600 400 900 200 700 100 550 350 750 450 1000000000 1 15 100 1 8 200 5 12 150 3 10 50 7 15 100 1 15 50
Sample Output 4
10
Sample Input 5
1 1 1 1 1 1
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は、あるゲームセンターのイベントに参加しています。会場には N 行 M 列のグリッド状に並んだカードが掲示されており、各カードには 0 から 9 までの整数のポイントが書かれています。グリッドの i 行目 j 列目 (1 \leq i \leq N, 1 \leq j \leq M) のカードのポイントを a_{i,j} と表します。
高橋君は、このグリッドから長方形の領域をちょうど 1 つ選び、その領域内のすべてのカードを獲得します。ここで「長方形の領域」とは、上から r_1 行目から r_2 行目まで、かつ左から c_1 列目から c_2 列目まで(1 \leq r_1 \leq r_2 \leq N, 1 \leq c_1 \leq c_2 \leq M)に含まれるカード全体のことを指します。この領域の行数を h = r_2 - r_1 + 1、列数を w = c_2 - c_1 + 1 とすると、領域は h \times w 枚のカードを含みます。獲得したカードに書かれたポイントの合計が、高橋君のスコアとなります。
ただし、このイベントには「ぴったりルール」があります。選ぶ長方形領域に含まれるカードの枚数がちょうど K 枚でなければなりません。すなわち、h \times w = K を満たす必要があります。
高橋君が得られるスコアの最大値を求めてください。ぴったりルールを満たす長方形領域が 1 つも存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 200
- 1 \leq M \leq 200
- 1 \leq K \leq N \times M
- N, M, K はいずれも整数である
- S_i (1 \leq i \leq N) は長さ M の文字列であり、各文字は
0から9のいずれかである
入力
N M K S_1 S_2 \vdots S_N
1 行目には、グリッドの行数 N、列数 M、ぴったりルールで指定される枚数 K が、スペース区切りで与えられる。
続く N 行のうち i 行目 (1 \leq i \leq N) には、グリッドの i 行目のカードのポイントを左から順に並べた長さ M の文字列 S_i が与えられる。S_i の j 文字目は、グリッドの i 行目 j 列目のカードのポイント a_{i,j}(0 から 9 の整数)を表す。
出力
ぴったりルールを満たす長方形領域が存在する場合は、スコアの最大値を 1 行で出力せよ。存在しない場合は -1 を出力せよ。
入力例 1
3 4 6 1234 5678 9012
出力例 1
30
入力例 2
4 5 7 12345 67890 11111 99999
出力例 2
-1
入力例 3
5 6 12 193842 681937 274619 938271 526184
出力例 3
68
Score : 400 pts
Problem Statement
Takahashi is participating in an event at a game center. At the venue, cards are displayed in a grid of N rows and M columns, and each card has an integer point value from 0 to 9 written on it. The point value of the card at row i, column j (1 \leq i \leq N, 1 \leq j \leq M) of the grid is denoted as a_{i,j}.
Takahashi will select exactly one rectangular region from this grid and obtain all the cards within that region. A "rectangular region" refers to the set of all cards from row r_1 to row r_2 from the top, and from column c_1 to column c_2 from the left (1 \leq r_1 \leq r_2 \leq N, 1 \leq c_1 \leq c_2 \leq M). Letting the number of rows in this region be h = r_2 - r_1 + 1 and the number of columns be w = c_2 - c_1 + 1, the region contains h \times w cards. The sum of the point values written on the obtained cards becomes Takahashi's score.
However, this event has an "exact rule": the number of cards contained in the chosen rectangular region must be exactly K. In other words, the condition h \times w = K must be satisfied.
Find the maximum score Takahashi can achieve. If no rectangular region satisfying the exact rule exists, output -1.
Constraints
- 1 \leq N \leq 200
- 1 \leq M \leq 200
- 1 \leq K \leq N \times M
- N, M, K are all integers
- S_i (1 \leq i \leq N) is a string of length M, where each character is one of
0through9
Input
N M K S_1 S_2 \vdots S_N
The first line contains the number of rows N, the number of columns M, and the number of cards K specified by the exact rule, separated by spaces.
In the following N lines, the i-th line (1 \leq i \leq N) contains a string S_i of length M, representing the point values of the cards in row i of the grid from left to right. The j-th character of S_i represents the point value a_{i,j} (an integer from 0 to 9) of the card at row i, column j of the grid.
Output
If a rectangular region satisfying the exact rule exists, output the maximum score in one line. If no such region exists, output -1.
Sample Input 1
3 4 6 1234 5678 9012
Sample Output 1
30
Sample Input 2
4 5 7 12345 67890 11111 99999
Sample Output 2
-1
Sample Input 3
5 6 12 193842 681937 274619 938271 526184
Sample Output 3
68
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 433 点
問題文
高橋君は学校の文化祭でクイズ大会を企画しています。クイズ大会に参加する生徒は全部で N 人おり、生徒 i(1 \leq i \leq N)には実力値 A_i が設定されています。実力値が同じ生徒がいる場合でも、各生徒は異なる人物として区別されます。
高橋君はこの N 人の中からちょうど K 人を選んで 1 つのチームを作ります。このとき、各生徒は 1 回しか選べません。公平な大会にするため、選んだ K 人の実力値の合計が M の倍数になるようにしたいと考えています。
条件を満たす選び方が何通りあるか、10^9 + 7 で割った余りを求めてください。
ここで、正の整数 X が M の倍数であるとは、ある正の整数 k が存在して X = kM となることをいいます。
制約
- 1 \leq N \leq 30
- 1 \leq K \leq N
- 1 \leq M \leq 10^9
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N K M A_1 A_2 \ldots A_N
- 1 行目には、生徒の人数を表す整数 N 、選ぶ人数を表す整数 K 、倍数の基準となる整数 M が、スペース区切りで与えられる。
- 2 行目には、各生徒の実力値を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
N 人の生徒からちょうど K 人を選んだとき、実力値の合計が M の倍数となる選び方の数を 10^9 + 7 で割った余りを 1 行で出力せよ。
入力例 1
4 2 3 1 2 3 4
出力例 1
2
入力例 2
6 3 5 1 2 3 4 5 6
出力例 2
4
入力例 3
10 5 7 1 2 3 4 5 6 7 8 9 10
出力例 3
36
Score : 433 pts
Problem Statement
Takahashi is organizing a quiz competition for his school's cultural festival. There are N students participating in the quiz competition, and student i (1 \leq i \leq N) has a skill value A_i. Even if some students have the same skill value, each student is distinguished as a different person.
Takahashi will select exactly K people from these N students to form one team. Each student can only be selected once. To make the competition fair, he wants the sum of the skill values of the selected K people to be a multiple of M.
Find the number of ways to select the students that satisfy the condition, modulo 10^9 + 7.
Here, a positive integer X is a multiple of M if there exists a positive integer k such that X = kM.
Constraints
- 1 \leq N \leq 30
- 1 \leq K \leq N
- 1 \leq M \leq 10^9
- 1 \leq A_i \leq 10^9
- All inputs are integers
Input
N K M A_1 A_2 \ldots A_N
- The first line contains the integer N representing the number of students, the integer K representing the number of people to select, and the integer M which is the base for the multiple condition, separated by spaces.
- The second line contains the integers A_1, A_2, \ldots, A_N representing the skill values of each student, separated by spaces.
Output
Print on one line the number of ways to select exactly K people from N students such that the sum of their skill values is a multiple of M, modulo 10^9 + 7.
Sample Input 1
4 2 3 1 2 3 4
Sample Output 1
2
Sample Input 2
6 3 5 1 2 3 4 5 6
Sample Output 2
4
Sample Input 3
10 5 7 1 2 3 4 5 6 7 8 9 10
Sample Output 3
36