Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 100 点
問題文
すぬけ君は、1 から 12 までの整数を下図のようにグループ分けしました。 整数 x, y (1 ≤ x < y ≤ 12) が与えられるので、x, y が同一のグループに属しているか判定してください。
制約
- x, y は整数である。
- 1 ≤ x < y ≤ 12
入力
入力は以下の形式で標準入力から与えられる。
x y
出力
x, y が同一のグループに属しているならば Yes
を、そうでなければ No
を出力せよ。
入力例 1
1 3
出力例 1
Yes
入力例 2
2 4
出力例 2
No
Score : 100 points
Problem Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
Constraints
- x and y are integers.
- 1 ≤ x < y ≤ 12
Input
Input is given from Standard Input in the following format:
x y
Output
If x and y belong to the same group, print Yes
; otherwise, print No
.
Sample Input 1
1 3
Sample Output 1
Yes
Sample Input 2
2 4
Sample Output 2
No
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 200 点
問題文
縦 H ピクセル、横 W ピクセルの画像があります。 各ピクセルは英小文字で表されます。 上から i 番目、左から j 番目のピクセルは a_{ij} です。
この画像の周囲 1 ピクセルを #
で囲んだものを出力してください。
制約
- 1 ≤ H, W ≤ 100
- a_{ij} は英小文字である。
入力
入力は以下の形式で標準入力から与えられる。
H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
出力
画像の周囲 1 ピクセルを #
で囲んだものを出力せよ。
入力例 1
2 3 abc arc
出力例 1
##### #abc# #arc# #####
入力例 2
1 1 z
出力例 2
### #z# ###
Score : 200 points
Problem Statement
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}.
Put a box around this image and output the result. The box should consist of #
and have a thickness of 1.
Constraints
- 1 ≤ H, W ≤ 100
- a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
Output
Print the image surrounded by a box that consists of #
and has a thickness of 1.
Sample Input 1
2 3 abc arc
Sample Output 1
##### #abc# #arc# #####
Sample Input 2
1 1 z
Sample Output 2
### #z# ###
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 400 点
問題文
縦 H ブロック、横 W ブロックの板チョコがあります。 すぬけ君は、この板チョコをちょうど 3 つのピースに分割しようとしています。 ただし、各ピースはブロックの境目に沿った長方形でなければなりません。
すぬけ君は、3 つのピースの面積 (ブロック数) をできるだけ均等にしようとしています。 具体的には、3 つのピースの面積の最大値を S_{max}、最小値を S_{min} としたとき、S_{max} - S_{min} を最小化しようとしています。 S_{max} - S_{min} の最小値を求めてください。
制約
- 2 ≤ H, W ≤ 10^5
入力
入力は以下の形式で標準入力から与えられる。
H W
出力
S_{max} - S_{min} の最小値を出力せよ。
入力例 1
3 5
出力例 1
0
次図のように分割すると、S_{max} - S_{min} = 5 - 5 = 0 となります。
入力例 2
4 5
出力例 2
2
次図のように分割すると、S_{max} - S_{min} = 8 - 6 = 2 となります。
入力例 3
5 5
出力例 3
4
次図のように分割すると、S_{max} - S_{min} = 10 - 6 = 4 となります。
入力例 4
100000 2
出力例 4
1
入力例 5
100000 100000
出力例 5
50000
Score : 400 points
Problem Statement
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
Constraints
- 2 ≤ H, W ≤ 10^5
Input
Input is given from Standard Input in the following format:
H W
Output
Print the minimum possible value of S_{max} - S_{min}.
Sample Input 1
3 5
Sample Output 1
0
In the division below, S_{max} - S_{min} = 5 - 5 = 0.
Sample Input 2
4 5
Sample Output 2
2
In the division below, S_{max} - S_{min} = 8 - 6 = 2.
Sample Input 3
5 5
Sample Output 3
4
In the division below, S_{max} - S_{min} = 10 - 6 = 4.
Sample Input 4
100000 2
Sample Output 4
1
Sample Input 5
100000 100000
Sample Output 5
50000
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 500 点
問題文
N を 1 以上の整数とします。
長さ 3N の数列 a = (a_1, a_2, ..., a_{3N}) があります。 すぬけ君は、a からちょうど N 個の要素を取り除き、残った 2N 個の要素を元の順序で並べ、長さ 2N の数列 a' を作ろうとしています。 このとき、a' のスコアを (a' の前半 N 要素の総和) - (a' の後半 N 要素の総和) と定義します。
a' のスコアの最大値を求めてください。
制約
- 1 ≤ N ≤ 10^5
- a_i は整数である。
- 1 ≤ a_i ≤ 10^9
部分点
- 300 点分のテストケースでは、N ≤ 1,000 が成り立つ。
入力
入力は以下の形式で標準入力から与えられる。
N a_1 a_2 ... a_{3N}
出力
a' のスコアの最大値を出力せよ。
入力例 1
2 3 1 4 1 5 9
出力例 1
1
a_2, a_6 を取り除くと、a' = (3, 4, 1, 5) となり、スコアは (3 + 4) - (1 + 5) = 1 となります。
入力例 2
1 1 2 3
出力例 2
-1
例えば、a_1 を取り除くと、a' = (2, 3) となり、スコアは 2 - 3 = -1 となります。
入力例 3
3 8 2 2 7 4 6 5 3 8
出力例 3
5
例えば、a_2, a_3, a_9 を取り除くと、a' = (8, 7, 4, 6, 5, 3) となり、スコアは (8 + 7 + 4) - (6 + 5 + 3) = 5 となります。
Score : 500 points
Problem Statement
Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').
Find the maximum possible score of a'.
Constraints
- 1 ≤ N ≤ 10^5
- a_i is an integer.
- 1 ≤ a_i ≤ 10^9
Partial Score
- In the test set worth 300 points, N ≤ 1000.
Input
Input is given from Standard Input in the following format:
N a_1 a_2 ... a_{3N}
Output
Print the maximum possible score of a'.
Sample Input 1
2 3 1 4 1 5 9
Sample Output 1
1
When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.
Sample Input 2
1 1 2 3
Sample Output 2
-1
For example, when a_1 are removed, a' will be (2, 3), which has a score of 2 - 3 = -1.
Sample Input 3
3 8 2 2 7 4 6 5 3 8
Sample Output 3
5
For example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3), which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5.