実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は縦 A cm、横 B cm の長方形の色紙を持っています。
高橋君はこの色紙から、 1 辺が C cm の正方形をできるだけ多く切り出したいです。ただし、正方形の辺は色紙の辺と平行になるように切り、切り出した正方形どうしが重なってはいけません。
切り出せる正方形の最大の枚数を求めてください。
制約
- 1 \leq A \leq 1000
- 1 \leq B \leq 1000
- 1 \leq C \leq 1000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
- 1 行目には、色紙の縦の長さ A 、横の長さ B 、正方形の 1 辺の長さ C がスペース区切りで与えられる。
出力
切り出せる正方形の最大の枚数を 1 行で出力せよ。
入力例 1
4 6 2
出力例 1
6
入力例 2
1 1 2
出力例 2
0
入力例 3
9 3 3
出力例 3
3
入力例 4
540 973 452
出力例 4
2
入力例 5
999 1000 1
出力例 5
999000
Score : 200 pts
Problem Statement
Takahashi has a rectangular sheet of colored paper (shikishi) that is A cm tall and B cm wide.
He wants to cut out as many squares with side length C cm as possible from this sheet. The squares must be cut so that their sides are parallel to the sides of the sheet, and the cut-out squares must not overlap each other.
Find the maximum number of squares that can be cut out.
Constraints
- 1 \leq A \leq 1000
- 1 \leq B \leq 1000
- 1 \leq C \leq 1000
- All input values are integers.
Input
The input is given from standard input in the following format:
A B C
- The first line contains the height of the sheet A, the width of the sheet B, and the side length of the square C, separated by spaces.
Output
Print the maximum number of squares that can be cut out in one line.
Sample Input 1
4 6 2
Sample Output 1
6
Sample Input 2
1 1 2
Sample Output 2
0
Sample Input 3
9 3 3
Sample Output 3
3
Sample Input 4
540 973 452
Sample Output 4
2
Sample Input 5
999 1000 1
Sample Output 5
999000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 266 点
問題文
高橋君は、横一列に並んだ N 個のマスからなる壁を塗装しようとしています。
マスには左から順に 1 から N までの番号が付けられています。
はじめ、すべてのマスはペンキで塗られていません。
各マスに障害物があるかどうかは、長さ N の文字列 S によって表されます。
S の i 文字目が # のときマス i には障害物があり、. のときマス i には障害物がありません。
高橋君は幅 K のローラーを使って、以下の操作を何回でも行うことができます。
- 障害物のない連続する K 個のマスを選び、それらをすべてペンキで塗る。
厳密には、1 \leq i \leq N - K + 1 かつマス i, i+1, \dots, i+K-1 のいずれにも障害物がない(すなわち、S の i 文字目から i+K-1 文字目までがすべて . である)ような整数 i を選び、マス i, i+1, \dots, i+K-1 をすべてペンキで塗る。
同じマスを複数回塗っても構いません。
高橋君の目標は、障害物のないすべてのマスが 1 回以上塗られた状態にすることです。
目標を達成するために必要な操作回数の最小値を求めてください。ただし、目標を達成することが不可能な場合は -1 を出力してください。
なお、はじめから障害物のないマスが 1 つも存在しない場合、すでに目標は達成されているとみなし、必要な操作回数は 0 回とします。
制約
- 1 \leq N \leq 2 \times 10^6
- 1 \leq K \leq N
- S は
.および#のみからなる長さ N の文字列 - N, K は整数
入力
入力は以下の形式で与えられる。
N K S
出力
目標を達成するために必要な操作回数の最小値を出力せよ。ただし、目標を達成することが不可能な場合は -1 を出力せよ。
入力例 1
8 3 ...#....
出力例 1
3
入力例 2
7 3 ..#....
出力例 2
-1
入力例 3
25 4 #....##.......#....#.....
出力例 3
6
入力例 4
65 5 .....#..........##.....#...............#......#........##########
出力例 4
11
入力例 5
4 3 ####
出力例 5
0
Score : 266 pts
Problem Statement
Takahashi is trying to paint a wall consisting of N squares arranged in a horizontal row.
The squares are numbered 1 to N from left to right.
Initially, no square is painted.
Whether each square has an obstacle is represented by a string S of length N.
If the i-th character of S is #, square i has an obstacle; if it is ., square i does not have an obstacle.
Using a roller of width K, Takahashi can perform the following operation any number of times:
- Choose K consecutive squares without obstacles and paint all of them.
Strictly speaking, choose an integer i such that 1 \leq i \leq N - K + 1 and none of the squares i, i+1, \dots, i+K-1 have an obstacle (that is, the i-th through (i+K-1)-th characters of S are all .), and paint all squares i, i+1, \dots, i+K-1.
A square may be painted multiple times.
Takahashi's goal is to reach a state where every square without an obstacle has been painted at least once.
Find the minimum number of operations required to achieve this goal. If it is impossible to achieve the goal, output -1.
Note that if there are no obstacle-free squares from the beginning, the goal is considered already achieved, and the required number of operations is 0.
Constraints
- 1 \leq N \leq 2 \times 10^6
- 1 \leq K \leq N
- S is a string of length N consisting of
.and#. - N and K are integers.
Input
The input is given from Standard Input in the following format:
N K S
Output
Print the minimum number of operations required to achieve the goal. If it is impossible to achieve the goal, print -1.
Sample Input 1
8 3 ...#....
Sample Output 1
3
Sample Input 2
7 3 ..#....
Sample Output 2
-1
Sample Input 3
25 4 #....##.......#....#.....
Sample Output 3
6
Sample Input 4
65 5 .....#..........##.....#...............#......#........##########
Sample Output 4
11
Sample Input 5
4 3 ####
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君は、りんご園で一列に並んだ \(N\) 本のりんごの木からりんごを収穫しようとしています。\(i\) 番目の木(\(1 \leq i \leq N\))からは \(A_i\) 個のりんごが収穫できますが、 1 本の木を収穫するごとにコスト \(C\) がかかります。
高橋君は、連続した区間の木を選び、その区間に含まれるすべての木からりんごを収穫します。\(l\) 番目から \(r\) 番目(\(1 \le l \le r \le N\))までの木を選んだとき、得られる利益は次の式で計算されます。
- \displaystyle \left(\sum_{i=l}^{r} A_i\right) - (r - l + 1) \times C
また、 1 本も木を選ばないことも許され、その場合の利益は \(0\) です。
高橋君が得られる利益の最大値を求めてください。
制約
- \(1 \leq N \leq 150000\)
- \(1 \leq C \leq 10^9\)
- \(0 \leq A_i \leq 10^9\)
- 入力はすべて整数である。
入力
入力は以下の形式で与えられる。
N C A_1 A_2 \vdots A_N
1 行目には、木の本数 \(N\) と 1 本あたりのコスト \(C\) がスペース区切りで与えられる。続く \(N\) 行のうち \(i\) 行目(\(1 \leq i \leq N\))には、\(i\) 番目の木から収穫できるりんごの個数 \(A_i\) が与えられる。
出力
高橋君が得られる利益の最大値を 1 行で出力せよ。
入力例 1
5 3 4 1 6 2 5
出力例 1
4
入力例 2
4 5 1 2 4 0
出力例 2
0
入力例 3
12 4 3 10 2 8 1 7 9 0 6 5 11 2
出力例 3
19
入力例 4
20 500000000 900000000 100000000 800000000 700000000 200000000 1000000000 300000000 900000000 400000000 600000000 500000000 1000000000 100000000 800000000 900000000 200000000 700000000 1000000000 500000000 600000000
出力例 4
2200000000
入力例 5
1 1000000000 1000000000
出力例 5
0
Score : 333 pts
Problem Statement
Takahashi is going to harvest apples from \(N\) apple trees lined up in a row in an apple orchard. From the \(i\)-th tree (\(1 \leq i \leq N\)), \(A_i\) apples can be harvested, but each tree harvested incurs a cost of \(C\).
Takahashi will choose a contiguous range of trees and harvest apples from all the trees within that range. When choosing the trees from the \(l\)-th to the \(r\)-th (\(1 \le l \le r \le N\)), the profit obtained is calculated by the following formula:
- \displaystyle \left(\sum_{i=l}^{r} A_i\right) - (r - l + 1) \times C
He is also allowed not to choose any trees at all, in which case the profit is \(0\).
Find the maximum profit Takahashi can obtain.
Constraints
- \(1 \leq N \leq 150000\)
- \(1 \leq C \leq 10^9\)
- \(0 \leq A_i \leq 10^9\)
- All input values are integers.
Input
The input is given in the following format:
N C A_1 A_2 \vdots A_N
The first line contains the number of trees \(N\) and the cost per tree \(C\), separated by a space. The \(i\)-th line of the following \(N\) lines (\(1 \leq i \leq N\)) contains the number of apples \(A_i\) that can be harvested from the \(i\)-th tree.
Output
Print the maximum profit Takahashi can obtain in a single line.
Sample Input 1
5 3 4 1 6 2 5
Sample Output 1
4
Sample Input 2
4 5 1 2 4 0
Sample Output 2
0
Sample Input 3
12 4 3 10 2 8 1 7 9 0 6 5 11 2
Sample Output 3
19
Sample Input 4
20 500000000 900000000 100000000 800000000 700000000 200000000 1000000000 300000000 900000000 400000000 600000000 500000000 1000000000 100000000 800000000 900000000 200000000 700000000 1000000000 500000000 600000000
Sample Output 4
2200000000
Sample Input 5
1 1000000000 1000000000
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
海を真上から見た二次元平面上に N 匹の魚がいます。i 番目の魚は座標 (X_i, Y_i) にいます。同じ座標に複数の魚が存在することもあります。
高橋君は、x 軸方向の長さが W、y 軸方向の長さが H の長方形の網を 1 回だけ使って、できるだけ多くの魚を捕まえたいと考えています。
網の各辺は x 軸または y 軸に平行になるように置く必要があり、回転させることはできません。網は平面上の任意の実数座標の位置に置くことができます。具体的には、ある実数 a, b を選び、左下の頂点が (a, b) となるように網を置くと、長方形領域 a \leq x \leq a + W かつ b \leq y \leq b + H の内部または辺上にいる魚をすべて捕まえることができます。
高橋君が捕まえることのできる魚の数の最大値を求めてください。
制約
- 1 \leq N \leq 3000
- 1 \leq W \leq 10^9
- 1 \leq H \leq 10^9
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- 入力はすべて整数である
入力
N W H X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
1 行目には、魚の数 N、網の x 軸方向の長さ W、網の y 軸方向の長さ H がスペース区切りで与えられる。続く N 行のうち i 行目には、i 番目の魚の座標 X_i, Y_i がスペース区切りで与えられる。
出力
高橋君が捕まえることのできる魚の数の最大値を 1 行で出力せよ。
入力例 1
5 2 2 0 0 1 1 2 2 3 0 0 3
出力例 1
3
入力例 2
6 1 1 0 0 0 0 1 1 1 0 2 1 -1 -1
出力例 2
4
入力例 3
12 4 3 -3 0 -2 1 -1 2 0 0 1 1 2 2 3 3 4 1 5 0 6 2 1 4 2 -1
出力例 3
6
入力例 4
20 5 4 -5 -5 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 1 6 2 7 3 8 4 9 5 2 0 2 0 3 1 3 1 10 10
出力例 4
9
入力例 5
1 1 1 1000000000 -1000000000
出力例 5
1
Score : 400 pts
Problem Statement
On a two-dimensional plane viewing the sea from directly above, there are N fish. The i-th fish is located at coordinates (X_i, Y_i). Multiple fish may exist at the same coordinates.
Takahashi wants to catch as many fish as possible using a rectangular net of length W in the x-axis direction and length H in the y-axis direction, which he can use exactly once.
Each side of the net must be placed parallel to the x-axis or y-axis, and it cannot be rotated. The net can be placed at any position with real-valued coordinates on the plane. Specifically, by choosing real numbers a, b and placing the net so that its bottom-left corner is at (a, b), he can catch all fish that are inside or on the boundary of the rectangular region a \leq x \leq a + W and b \leq y \leq b + H.
Find the maximum number of fish that Takahashi can catch.
Constraints
- 1 \leq N \leq 3000
- 1 \leq W \leq 10^9
- 1 \leq H \leq 10^9
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- All input values are integers
Input
N W H X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
The first line contains the number of fish N, the length of the net in the x-axis direction W, and the length of the net in the y-axis direction H, separated by spaces. Each of the following N lines contains the coordinates X_i, Y_i of the i-th fish, separated by spaces.
Output
Print the maximum number of fish that Takahashi can catch, on a single line.
Sample Input 1
5 2 2 0 0 1 1 2 2 3 0 0 3
Sample Output 1
3
Sample Input 2
6 1 1 0 0 0 0 1 1 1 0 2 1 -1 -1
Sample Output 2
4
Sample Input 3
12 4 3 -3 0 -2 1 -1 2 0 0 1 1 2 2 3 3 4 1 5 0 6 2 1 4 2 -1
Sample Output 3
6
Sample Input 4
20 5 4 -5 -5 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 1 6 2 7 3 8 4 9 5 2 0 2 0 3 1 3 1 10 10
Sample Output 4
9
Sample Input 5
1 1 1 1000000000 -1000000000
Sample Output 5
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 466 点
問題文
数直線上でスタンプラリーが開催されています。
数直線上には 1 から N までの番号が付けられた N 箇所のチェックポイントがあります。チェックポイント i は座標 X_i に設置されており、スタンプの獲得期限は時刻 T_i です。
高橋君は時刻 0 に座標 0 を出発し、数直線上を最大で速さ 1 で移動することができます(移動する向きの反転や停止はいつでも自由に行えます)。
高橋君は、時刻 T_i 以前に座標 X_i に到達することで、チェックポイント i のスタンプを 1 つ獲得できます(その座標を通過するだけでも獲得できます)。ただし、各チェックポイントのスタンプは 1 つまでしか獲得できず、スタンプの獲得にかかる時間は無視できます。
高橋君が最適に行動したとき、獲得できるスタンプの個数の最大値を求めてください。
制約
- 1 \leq N \leq 100
- -10^9 \leq X_i \leq 10^9 (1 \leq i \leq N)
- X_i \neq 0 (1 \leq i \leq N)
- X_i \neq X_j (1 \leq i < j \leq N)
- 0 \leq T_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N X_1 T_1 X_2 T_2 \vdots X_N T_N
出力
高橋君が獲得できるスタンプの個数の最大値を 1 行で出力してください。
入力例 1
3 1 3 -2 5 4 4
出力例 1
2
入力例 2
3 5 2 -10 8 100 50
出力例 2
0
入力例 3
12 -35 80 -20 30 -12 15 -5 7 -2 2 3 4 8 10 15 25 25 50 40 90 -60 120 70 110
出力例 3
6
入力例 4
30 -892301492 900000000 -820194821 850000000 -749102840 800000000 -681920491 750000000 -610294819 700000000 -549102948 600000000 -481920394 550000000 -419204918 500000000 -359102948 450000000 -281920491 350000000 -210294819 300000000 -149102948 200000000 -81920394 100000000 -29102948 50000000 -10294819 20000000 15920394 25000000 34910294 40000000 78192039 90000000 139102948 180000000 201920491 250000000 270294819 320000000 349102948 400000000 410294819 480000000 479102948 550000000 541920491 620000000 610294819 700000000 679102948 780000000 741920491 850000000 810294819 920000000 889102948 990000000
出力例 4
15
入力例 5
1 -1000000000 1000000000
出力例 5
1
Score : 466 pts
Problem Statement
A stamp rally is being held on a number line.
There are N checkpoints on the number line, numbered 1 through N. Checkpoint i is located at coordinate X_i, and the deadline to collect its stamp is time T_i.
Takahashi starts at coordinate 0 at time 0, and can move along the number line at a speed of at most 1 (he can change direction or stop at any time).
By reaching coordinate X_i at or before time T_i, Takahashi can collect the stamp of checkpoint i (merely passing through that coordinate is sufficient to collect it). However, he can collect at most one stamp from each checkpoint, and the time required to collect a stamp is negligible.
Find the maximum number of stamps Takahashi can collect if he acts optimally.
Constraints
- 1 \leq N \leq 100
- -10^9 \leq X_i \leq 10^9 (1 \leq i \leq N)
- X_i \neq 0 (1 \leq i \leq N)
- X_i \neq X_j (1 \leq i < j \leq N)
- 0 \leq T_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
The input is given in the following format:
N X_1 T_1 X_2 T_2 \vdots X_N T_N
Output
Print the maximum number of stamps Takahashi can collect in a single line.
Sample Input 1
3 1 3 -2 5 4 4
Sample Output 1
2
Sample Input 2
3 5 2 -10 8 100 50
Sample Output 2
0
Sample Input 3
12 -35 80 -20 30 -12 15 -5 7 -2 2 3 4 8 10 15 25 25 50 40 90 -60 120 70 110
Sample Output 3
6
Sample Input 4
30 -892301492 900000000 -820194821 850000000 -749102840 800000000 -681920491 750000000 -610294819 700000000 -549102948 600000000 -481920394 550000000 -419204918 500000000 -359102948 450000000 -281920491 350000000 -210294819 300000000 -149102948 200000000 -81920394 100000000 -29102948 50000000 -10294819 20000000 15920394 25000000 34910294 40000000 78192039 90000000 139102948 180000000 201920491 250000000 270294819 320000000 349102948 400000000 410294819 480000000 479102948 550000000 541920491 620000000 610294819 700000000 679102948 780000000 741920491 850000000 810294819 920000000 889102948 990000000
Sample Output 4
15
Sample Input 5
1 -1000000000 1000000000
Sample Output 5
1