実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋くんは、頭パーツを 1 個と体パーツを 1 個組み合わせてロボットを 1 体作ることができます。 ロボットは頭パーツの重さが体パーツの重さより大きいと倒れてしまいます。
現在、高橋くんは頭パーツと体パーツを 1 個ずつ持っています。 高橋くんが持っている頭パーツの重さは H グラム、体パーツの重さは B グラムです。
高橋くんは、体パーツを重くすることで、ロボットを倒れないようにしたいです。 高橋くんが作るロボットが倒れないようにするためには、体パーツをあと何グラム重くする必要があるか求めてください。
制約
- 1\le H\le100
- 1\le B\le100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H B
出力
答えを出力せよ。
入力例 1
43 1
出力例 1
42
高橋くんは、体パーツを 42 グラム重くすることで、頭パーツと体パーツの重さを等しくすることができます。
体パーツを重くする量が 42 グラム未満のとき、高橋くんが作るロボットは倒れてしまうため、42 を出力してください。
入力例 2
4 31
出力例 2
0
高橋くんがこのままロボットを作ってもロボットは倒れないため、0 を出力してください。
入力例 3
1 1
出力例 3
0
Score : 100 points
Problem Statement
Takahashi can combine a head part and a body part to create a robot. A robot falls over if the weight of the head part is greater than the weight of the body part.
Currently, he has one head part and one body part. The weight of the head part is H grams, and the weight of the body part is B grams.
He wants to make the body part heavier so that the robot does not fall over. Find how many more grams the body part needs to be made heavier so that his robot does not fall over.
Constraints
- 1\le H\le100
- 1\le B\le100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H B
Output
Print the answer.
Sample Input 1
43 1
Sample Output 1
42
By making the body part 42 grams heavier, Takahashi can make the weights of the head part and body part equal.
When the amount by which the body part is made heavier is less than 42 grams, his robot will fall over, so print 42.
Sample Input 2
4 31
Sample Output 2
0
Even if he creates the robot as is, the robot will not fall over, so print 0.
Sample Input 3
1 1
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
あなたはコワスギ銀行の通帳を持っています。コワスギ銀行の預金通帳には、引き出し額に応じて手数料が変わるという怖すぎる性質があります。
コワスギ銀行の通帳からお金を引き出すには、1\,000 円単位で引き出し額を指定したうえで、引き出し額 1\,000 円あたり C 円の手数料を残高から別途支払う必要があります。銀行の残高が 0 円未満になる引き出しを行うことはできません。
あなたが持っているコワスギ銀行の通帳の残高が X 円のとき、そこから最大で何円を引き出せますか?
制約
- 1 \leq X \leq 10^7
- 1 \leq C \leq 999
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X C
出力
答えを出力せよ。
入力例 1
650000 8
出力例 1
644000
644\,000 円を引き出すために必要な手数料は 644\,000 \times \displaystyle\frac{8}{1000} = 5\,152 円になるので、644\,000 + 5\,152 \leq 650\,000 より、644\,000 円は引き出すことができます。
一方で、645\,000 円引き出すために必要な手数料は 645\,000 \times \displaystyle\frac{8}{1000} = 5\,160 円になるので、645\,000 + 5\,160 > 650\,000 より、645\,000 円は引き出すことができません。
入力例 2
1003 4
出力例 2
0
まったくお金が引き出せないこともありえます。
入力例 3
10000000 24
出力例 3
9765000
Score : 150 points
Problem Statement
You have a bankbook from The Terrifying Bank. The deposit passbook of the bank has a terrifyingly scary property that the commission fee changes according to the withdrawal amount.
To withdraw money from the passbook, you need to specify the withdrawal amount in units of 1\,000 yen, and pay a commission fee of C yen per 1\,000 yen of withdrawal amount separately from the balance. Withdrawals are not allowed if they would leave the balance below 0 yen.
When the balance of your passbook from the bank is X yen, what is the maximum amount of money you can withdraw from it?
Constraints
- 1 \leq X \leq 10^7
- 1 \leq C \leq 999
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X C
Output
Output the answer.
Sample Input 1
650000 8
Sample Output 1
644000
The commission fee required to withdraw 644\,000 yen is 644\,000 \times \displaystyle\frac{8}{1000} = 5\,152 yen, so since 644\,000 + 5\,152 \leq 650\,000, you can withdraw 644\,000 yen.
On the other hand, the commission fee required to withdraw 645\,000 yen is 645\,000 \times \displaystyle\frac{8}{1000} = 5\,160 yen, so since 645\,000 + 5\,160 > 650\,000, you cannot withdraw 645\,000 yen.
Sample Input 2
1003 4
Sample Output 2
0
It is possible that no money can be withdrawn at all.
Sample Input 3
10000000 24
Sample Output 3
9765000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
0 と 1 からなる長さ 64 の数列 A=(A_0,A_1,\dots,A_{63}) が与えられます。
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} を求めてください。
制約
- A_i は 0 または 1
入力
入力は以下の形式で標準入力から与えられる。
A_0 A_1 \dots A_{63}
出力
答えを整数として出力せよ。
入力例 1
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
出力例 1
13
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13 です。
入力例 2
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0
出力例 2
766067858140017173
Score : 200 points
Problem Statement
You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1.
Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}.
Constraints
- A_i is 0 or 1.
Input
The input is given from Standard Input in the following format:
A_0 A_1 \dots A_{63}
Output
Print the answer as an integer.
Sample Input 1
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 1
13
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13.
Sample Input 2
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0
Sample Output 2
766067858140017173
実行時間制限: 2 sec / メモリ制限: 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.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
この問題における 11/22 文字列の定義は A 問題および E 問題と同じです。
文字列 T が以下の条件を全て満たすとき、T を 11/22 文字列 と呼びます。
- |T| は奇数である。ここで、|T| は T の長さを表す。
- 1 文字目から \frac{|T|+1}{2} - 1 文字目までが
1である。 - \frac{|T|+1}{2} 文字目が
/である。 - \frac{|T|+1}{2} + 1 文字目から |T| 文字目までが
2である。
例えば 11/22, 111/222, / は 11/22 文字列ですが、1122, 1/22, 11/2222, 22/11, //2/2/211 はそうではありません。
1, 2, / からなる長さ N の文字列 S が与えられます。S は / を 1 個以上含みます。
11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- S は
1,2,/からなる長さ N の文字列 - S は
/を 1 個以上含む
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を出力せよ。
入力例 1
8 211/2212
出力例 1
5
S の 2 文字目から 6 文字目からなる部分文字列は 11/22 で、これは 11/22 文字列です。S の部分文字列のうち 11/22 文字列であるものはこれが最長です。よって 5 が答えです。
入力例 2
5 22/11
出力例 2
1
入力例 3
22 /1211/2///2111/2222/11
出力例 3
7
Score : 300 points
Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems A and E.
A string T is called an 11/22 string when it satisfies all of the following conditions:
- |T| is odd. Here, |T| denotes the length of T.
- The 1-st through (\frac{|T|+1}{2} - 1)-th characters are all
1. - The (\frac{|T|+1}{2})-th character is
/. - The (\frac{|T|+1}{2} + 1)-th through |T|-th characters are all
2.
For example, 11/22, 111/222, and / are 11/22 strings, but 1122, 1/22, 11/2222, 22/11, and //2/2/211 are not.
You are given a string S of length N consisting of 1, 2, and /, where S contains at least one /.
Find the maximum length of a (contiguous) substring of S that is an 11/22 string.
Constraints
- 1 \leq N \leq 2 \times 10^5
- S is a string of length N consisting of
1,2, and/. - S contains at least one
/.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the maximum length of a (contiguous) substring of S that is an 11/22 string.
Sample Input 1
8 211/2212
Sample Output 1
5
The substring from the 2-nd to 6-th character of S is 11/22, which is an 11/22 string. Among all substrings of S that are 11/22 strings, this is the longest. Therefore, the answer is 5.
Sample Input 2
5 22/11
Sample Output 2
1
Sample Input 3
22 /1211/2///2111/2222/11
Sample Output 3
7