実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
AtCoder 市では市長選挙が行われています。候補者は高橋氏と青木氏です。
2 人のどちらかに投じられた有効票は N 票あり、現在開票が行われています。なお、 N は奇数です。
現在の開票作業の途中経過は高橋氏に T 票、青木氏に A 票です。
現時点で勝敗が確定しているかを判定してください。
制約
- 1 \leq N \leq 99
- N は奇数
- 0 \leq T,A \leq N
- T+A \leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T A
出力
現時点で勝敗が確定しているならば Yes 、そうでなければ No と出力せよ。
入力例 1
7 4 2
出力例 1
Yes
残りの 1 票が青木氏に入っても、高橋氏は勝利します。高橋氏の勝利が確定しているため、Yes と出力します。
入力例 2
99 12 48
出力例 2
No
現時点では青木氏が多く票を獲得していますが、高橋氏が残りの 39 票を獲得すると高橋氏が勝利します。よって、No と出力します。
入力例 3
1 0 0
出力例 3
No
Score : 100 points
Problem Statement
A mayoral election is being held in AtCoder City. The candidates are Takahashi and Aoki.
There are N valid votes cast for either of the two candidates, and the counting is currently underway. Here, N is an odd number.
The current vote count is T votes for Takahashi and A votes for Aoki.
Determine if the outcome of the election is already decided at this point.
Constraints
- 1 \leq N \leq 99
- N is an odd number.
- 0 \leq T, A \leq N
- T + A \leq N
- All input values are integers.
Input
The input is given from standard input in the following format:
N T A
Output
Print Yes if the outcome of the election is already decided, and No otherwise.
Sample Input 1
7 4 2
Sample Output 1
Yes
Even if the remaining one vote goes to Aoki, Takahashi will still win. That is, his victory is decided, so print Yes.
Sample Input 2
99 12 48
Sample Output 2
No
Although Aoki currently has more votes, Takahashi would win if he receives the remaining 39 votes. Therefore, print No.
Sample Input 3
1 0 0
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋くんは満月が好きです。
今日を 1 日目とすると、今日以降で満月を見られる最初の日は M 日目です。以後は P 日ごと、つまり M+P 日目、M+2P 日目、\ldots に満月を見られます。
1 日目から N 日目まで(両端を含む)の中で、高橋くんが満月を見られる日の数を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq M \leq P \leq 2\times 10^5
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M P
出力
答えを整数として出力せよ。
入力例 1
13 3 5
出力例 1
3
満月を見られる日は、3 日目、8 日目、13 日目、18 日目、\ldots です。
1 日目から 13 日目までの中で高橋くんが満月を見られる日は、3 日目、8 日目、13 日目の 3 個です。
入力例 2
5 6 6
出力例 2
0
高橋くんが満月を見られる日が存在しない場合もあります。
入力例 3
200000 314 318
出力例 3
628
Score : 100 points
Problem Statement
Takahashi likes full moons.
Let today be day 1. The first day on or after today on which he can see a full moon is day M. After that, he can see a full moon every P days, that is, on day M+P, day M+2P, and so on.
Find the number of days between day 1 and day N, inclusive, on which he can see a full moon.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq M \leq P \leq 2\times 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M P
Output
Print the answer as an integer.
Sample Input 1
13 3 5
Sample Output 1
3
He can see a full moon on day 3, 8, 13, 18, and so on.
From day 1 to 13, he can see a full moon on three days: day 3, 8, and 13.
Sample Input 2
5 6 6
Sample Output 2
0
There may be no days he can see a full moon.
Sample Input 3
200000 314 318
Sample Output 3
628
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の人が、M 問からなるプログラミングコンテストに参加しました。
参加者は人 1, 人 2, \ldots, 人 N と番号づけられており、問題は問題 1, 問題 2, \ldots, 問題 M と番号づけられています。
このコンテストでは K 個のイベントが順番に起き、i 番目 (1\leq i\leq K) のイベントでは次のことが起きました。
- 人 A_i が問題 B_i に正解した。
同じイベントが 2 回以上起きることはありません。 また、この K 個のイベント以外に誰かがどれかの問題に正解することはありません。
すべての問題に正解した人の番号を全員出力してください。
そのような人が複数いる場合は、すべての問題に正解したタイミングが早い順に出力してください。
制約
- 1 \leq N \leq 10
- 1 \leq M \leq 10
- K \geq 1
- 1 \leq A_i\leq N
- 1 \leq B_i\leq M
- i\neq j ならば (A_i,B_i)\neq (A_j,B_j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 B_1 A_2 B_2 \vdots A_K B_K
出力
すべての問題に正解した人の番号を、すべての問題に正解したタイミングが早い順に空白区切りで一行に出力せよ。
すべての問題に正解した人がいないならば、何も出力しないようにせよ。
入力例 1
3 2 5 1 1 3 2 2 1 3 1 1 2
出力例 1
3 1
コンテストでは次のことが順に起きました。
- 人 1 が問題 1 に正解した。人 1 はこれまでに、問題 1 のみに正解した。
- 人 3 が問題 2 に正解した。人 3 はこれまでに、問題 2 のみに正解した。
- 人 2 が問題 1 に正解した。人 2 はこれまでに、問題 1 のみに正解した。
- 人 3 が問題 1 に正解した。人 3 はこれまでに、問題 1,2 に正解した。よって、この時点で人 3 はすべての問題に正解した。
- 人 1 が問題 2 に正解した。人 1 はこれまでに、問題 1,2 に正解した。よって、この時点で人 1 はすべての問題に正解した。
よって、すべての問題に正解したのは人 1,3 であり、すべての問題に正解したタイミングは人 3 の方が早いです。
よって、3,1 をこの順に空白区切りで出力します。
入力例 2
2 2 2 1 1 2 2
出力例 2
すべての問題に正解した人がいない場合は、何も出力しないでください。
Score : 200 points
Problem Statement
N people participated in a programming contest consisting of M problems.
The participants are numbered person 1, person 2, \ldots, person N, and the problems are numbered problem 1, problem 2, \ldots, problem M.
In this contest, K events occurred in order; in the i-th event (1\leq i\leq K), the following happened:
- Person A_i solved problem B_i.
The same event does not occur two or more times. Also, apart from these K events, nobody solves any problem.
Output the numbers of all people who solved all problems.
If there are multiple such people, output them in ascending order of the time at which they solved all problems.
Constraints
- 1 \leq N \leq 10
- 1 \leq M \leq 10
- K \geq 1
- 1 \leq A_i \leq N
- 1 \leq B_i \leq M
- If i\neq j then (A_i,B_i)\neq (A_j,B_j).
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K A_1 B_1 A_2 B_2 \vdots A_K B_K
Output
Output, on one line and separated by spaces, the numbers of all people who solved all problems, in ascending order of the time at which they solved all problems. If there is no person who solved all problems, output nothing.
Sample Input 1
3 2 5 1 1 3 2 2 1 3 1 1 2
Sample Output 1
3 1
In the contest, the following happened in order.
- Person 1 solved problem 1. So far, person 1 has solved only problem 1.
- Person 3 solved problem 2. So far, person 3 has solved only problem 2.
- Person 2 solved problem 1. So far, person 2 has solved only problem 1.
- Person 3 solved problem 1. So far, person 3 has solved problems 1,2. Thus, at this point person 3 has solved all problems.
- Person 1 solved problem 2. So far, person 1 has solved problems 1,2. Thus, at this point person 1 has solved all problems.
Thus, the people who solved all problems are persons 1,3, and the one who solved all problems earlier is person 3. Thus, output 3,1 in this order, separated by spaces.
Sample Input 2
2 2 2 1 1 2 2
Sample Output 2
If there is no person who solved all problems, output nothing.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
九九の表に現れる 81 個の整数のうち、X でないものの総和を求めてください。
縦 9 マス、横 9 マスのグリッドがあります。
グリッドの各マスには整数が書きこまれていて、グリッドの上から i 行目、左から j 列目のマスには i \times j が書きこまれています。
整数 X が与えられます。グリッドに書きこまれた 81 個の整数のうち X でないものの総和を求めてください。値の等しい整数が異なるマスに書きこまれている場合は別々に加算する点に注意してください。
制約
- X は 1 以上 81 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
グリッドに書きこまれた 81 個の整数のうち X でないものの総和を出力せよ。
入力例 1
1
出力例 1
2024
グリッドに 1 が書きこまれたマスは上から 1 行目、左から 1 列目のマスのみです。1 でない整数を全て足し合わせると総和は 2024 になります。
入力例 2
11
出力例 2
2025
グリッドに 11 が書きこまれたマスは存在しません。よって 81 個の整数全てを足し合わせた総和である 2025 が答えとなります。
入力例 3
24
出力例 3
1929
Score : 150 points
Problem Statement
Among the 81 integers that appear in the 9-by-9 multiplication table, find the sum of those that are not X.
There is a grid of size 9 by 9.
Each cell of the grid contains an integer: the cell at the i-th row from the top and the j-th column from the left contains i \times j.
You are given an integer X. Among the 81 integers written in this grid, find the sum of those that are not X. If the same value appears in multiple cells, add it for each cell.
Constraints
- X is an integer between 1 and 81, inclusive.
Input
The input is given from Standard Input in the following format:
X
Output
Print the sum of the integers that are not X among the 81 integers written in the grid.
Sample Input 1
1
Sample Output 1
2024
The only cell with 1 in the grid is the cell at the 1st row from the top and 1st column from the left. Summing all integers that are not 1 yields 2024.
Sample Input 2
11
Sample Output 2
2025
There is no cell containing 11 in the grid. Thus, the answer is 2025, the sum of all 81 integers.
Sample Input 3
24
Sample Output 3
1929
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。
2 つの餅 A,B の大きさをそれぞれ a,b としたとき、a が b の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。
N 個の餅から 2 つの餅を選び、一方をもう一方の上に乗せることで鏡餅を 1 つ作ります。
何種類の鏡餅を作ることができるか求めてください。
ただし、鏡餅を構成する餅の大きさが同じでも、少なくとも一方が異なる餅であれば別の種類の鏡餅として数えます。
制約
- 2\leq N\leq 5\times 10 ^ 5
- 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
- A _ i\leq A _ {i+1}\ (1\leq i\lt N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \cdots A _ N
出力
作ることができる鏡餅の種類数を出力せよ。
入力例 1
6 2 3 4 4 7 10
出力例 1
8
与えられた餅の大きさは以下のようになっています。

このとき、以下の 8 種類の鏡餅を作ることができます。

大きさ 4 の餅の上に大きさ 2 の餅を乗せた鏡餅や、大きさ 10 の餅の上に大きさ 4 の餅を乗せた鏡餅は 2 種類あることに注意してください。
入力例 2
3 387 388 389
出力例 2
0
鏡餅を 1 種類も作ることができない場合もあります。
入力例 3
32 1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641
出力例 3
388
Score : 300 points
Problem Statement
There are N mochi (rice cakes) arranged in ascending order of size. The size of the i-th mochi (1 \leq i \leq N) is A_i.
Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.
You choose two mochi out of the N mochi, and place one on top of the other to form one kagamimochi.
Find how many different kinds of kagamimochi can be made.
Two kagamimochi are distinguished if at least one of the mochi is different, even if the sizes of the mochi are the same.
Constraints
- 2 \leq N \leq 5 \times 10^5
- 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
- A_i \leq A_{i+1} \ (1 \leq i < N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \cdots A_N
Output
Print the number of different kinds of kagamimochi that can be made.
Sample Input 1
6 2 3 4 4 7 10
Sample Output 1
8
The sizes of the given mochi are as follows:

In this case, you can make the following eight kinds of kagamimochi:

Note that there are two kinds of kagamimochi where a mochi of size 4 is topped by a mochi of size 2, and two kinds where a mochi of size 10 is topped by a mochi of size 4.
Sample Input 2
3 387 388 389
Sample Output 2
0
It is possible that you cannot make any kagamimochi.
Sample Input 3
32 1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641
Sample Output 3
388