Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は N 日間のタスク目標を設定しました。
高橋君は i (1 \leq i \leq N) 日目に A_i 個のタスクを完了することを目標としており、実際には B_i 個のタスクを完了しました。
高橋君が目標より多くのタスクを完了した日数を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i, B_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
答えを出力せよ。
入力例 1
4 2 8 5 5 5 4 6 7
出力例 1
2
高橋君は 1 日目と 4 日目に目標より多くのタスクを完了しました。
入力例 2
5 1 1 1 1 1 1 1 1 1 1
出力例 2
0
入力例 3
6 1 6 2 5 3 4 4 3 5 2 6 1
出力例 3
3
Score : 100 points
Problem Statement
Takahashi set task goals for N days.
He aimed to complete A_i tasks on day i (1 \leq i \leq N), and actually completed B_i tasks.
Find the number of days when he completed more tasks than his goal.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i, B_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Output the answer.
Sample Input 1
4 2 8 5 5 5 4 6 7
Sample Output 1
2
Takahashi completed more tasks than his goal on the 1st and 4th days.
Sample Input 2
5 1 1 1 1 1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
6 1 6 2 5 3 4 4 3 5 2 6 1
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1583 以上 2023 以下の整数 Y が与えられます。
西暦 Y 年の日数を求めてください。
なお、制約の範囲内では西暦 Y 年の日数は以下の通りです。
-
Y が 4 の倍数でない年は 365 日
-
Y が 4 の倍数で、かつ 100 の倍数でない年は 366 日
-
Y が 100 の倍数で、かつ 400 の倍数でない年は 365 日
-
Y が 400 の倍数である年は 366 日
制約
- Y は 1583 以上 2023 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
Y
出力
西暦 Y 年の日数を整数として出力せよ。
入力例 1
2023
出力例 1
365
2023 は 4 の倍数でないので 365 日です。
入力例 2
1992
出力例 2
366
1992 は 4 の倍数で、かつ 100 の倍数でないので 366 日です。
入力例 3
1800
出力例 3
365
1800 は 100 の倍数で、かつ 400 の倍数でないので 365 日です。
入力例 4
1600
出力例 4
366
1600 は 400 の倍数なので 366 日です。
Score : 100 points
Problem Statement
You are given an integer Y between 1583 and 2023.
Find the number of days in the year Y of the Gregorian calendar.
Within the given range, the year Y has the following number of days:
-
if Y is not a multiple of 4, then 365 days;
-
if Y is a multiple of 4 but not a multiple of 100, then 366 days;
-
if Y is a multiple of 100 but not a multiple of 400, then 365 days;
-
if Y is a multiple of 400, then 366 days.
Constraints
- Y is an integer between 1583 and 2023, inclusive.
Input
The input is given from Standard Input in the following format:
Y
Output
Print the number of days in the year Y as an integer.
Sample Input 1
2023
Sample Output 1
365
2023 is not a multiple of 4, so it has 365 days.
Sample Input 2
1992
Sample Output 2
366
1992 is a multiple of 4 but not a multiple of 100, so it has 366 days.
Sample Input 3
1800
Sample Output 3
365
1800 is a multiple of 100 but not a multiple of 400, so it has 365 days.
Sample Input 4
1600
Sample Output 4
366
1600 is a multiple of 400, so it has 366 days.
Time Limit: 2 sec / Memory Limit: 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.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
縦 H 行、横 W 列のマス目があり、各マスには 1 つの整数が書かれています。 上から i 行目、左から j 列目のマスに書かれている整数は A_{i, j} です。
マス目が下記の条件を満たすかどうかを判定してください。
1 \leq i_1 < i_2 \leq H および 1 \leq j_1 < j_2 \leq W を満たすすべての整数の組 (i_1, i_2, j_1, j_2) について、A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} が成り立つ。
制約
- 2 \leq H, W \leq 50
- 1 \leq A_{i, j} \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W
A_{1, 1} A_{1, 2} \cdots A_{1, W}
A_{2, 1} A_{2, 2} \cdots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \cdots A_{H, W}
出力
マス目が問題文中の条件を満たす場合は Yes と出力し、条件を満たさない場合は No と出力せよ。
入力例 1
3 3 2 1 4 3 1 3 6 4 1
出力例 1
Yes
1 \leq i_1 < i_2 \leq H および 1 \leq j_1 < j_2 \leq W を満たす整数の組 (i_1, i_2, j_1, j_2) は 9 個存在し、それらすべてについて A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} が成り立ちます。例えば、
- (i_1, i_2, j_1, j_2) = (1, 2, 1, 2) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 2, 1, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 2, 2, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 3, 1, 2) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}
- (i_1, i_2, j_1, j_2) = (1, 3, 1, 3) について、A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}
が成り立ちます。残りの (i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3) についても同様に確認できます。
よって、Yes を出力します。
入力例 2
2 4 4 3 2 1 5 6 7 8
出力例 2
No
問題文中の条件を満たさないので、No を出力します。
例えば、(i_1, i_2, j_1, j_2) = (1, 2, 1, 4) について、A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2} です。
Score : 200 points
Problem Statement
We have a grid with H horizontal rows and W vertical columns, where each square contains an integer. The integer written on the square at the i-th row from the top and j-th column from the left is A_{i, j}.
Determine whether the grid satisfies the condition below.
A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} holds for every quadruple of integers (i_1, i_2, j_1, j_2) such that 1 \leq i_1 < i_2 \leq H and 1 \leq j_1 < j_2 \leq W.
Constraints
- 2 \leq H, W \leq 50
- 1 \leq A_{i, j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W
A_{1, 1} A_{1, 2} \cdots A_{1, W}
A_{2, 1} A_{2, 2} \cdots A_{2, W}
\vdots
A_{H, 1} A_{H, 2} \cdots A_{H, W}
Output
If the grid satisfies the condition in the Problem Statement, print Yes; otherwise, print No.
Sample Input 1
3 3 2 1 4 3 1 3 6 4 1
Sample Output 1
Yes
There are nine quadruples of integers (i_1, i_2, j_1, j_2) such that 1 \leq i_1 < i_2 \leq H and 1 \leq j_1 < j_2 \leq W. For all of them, A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2} holds. Some examples follow.
- For (i_1, i_2, j_1, j_2) = (1, 2, 1, 2), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 2, 1, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 2, 2, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 3, 1, 2), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}.
- For (i_1, i_2, j_1, j_2) = (1, 3, 1, 3), we have A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}.
We can also see that the property holds for the other quadruples: (i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3).
Thus, we should print Yes.
Sample Input 2
2 4 4 3 2 1 5 6 7 8
Sample Output 2
No
We should print No because the condition is not satisfied.
This is because, for example, we have A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2} for (i_1, i_2, j_1, j_2) = (1, 2, 1, 4).
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の袋があります。
袋 i には L_i 個のボールが入っていて、袋 i の j(1\leq j\leq L_i) 番目のボールには正の整数 a_{i,j} が書かれています。
それぞれの袋から 1 つずつボールを取り出します。
取り出したボールに書かれた数の総積が X になるような取り出し方は何通りありますか?
ただし、書かれた数が同じであっても全てのボールは区別します。
制約
- N \geq 2
- L_i \geq 2
- 袋に入っているボールの個数の総積は 10^5 を超えない。すなわち、\displaystyle\prod_{i=1}^{N}L_i \leq 10^5
- 1 \leq a_{i,j} \leq 10^9
- 1 \leq X \leq 10^{18}
- 入力に含まれる値は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X
L_1 a_{1,1} a_{1,2} \ldots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \ldots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \ldots a_{N,L_N}
出力
答えを出力せよ。
入力例 1
2 40 3 1 8 4 2 10 5
出力例 1
2
袋 1 の 3 番目のボールと袋 2 の 1 番目のボールを選ぶと、a_{1,3} \times a_{2,1} = 4 \times 10 = 40 となります。
袋 1 の 2 番目のボールと袋 2 の 2 番目のボールを選ぶと、a_{1,2} \times a_{2,2} = 8 \times 5 = 40 となります。
これ以外に総積が 40 になる取り出し方は存在しないので、答えは 2 です。
入力例 2
3 200 3 10 10 10 3 10 10 10 5 2 2 2 2 2
出力例 2
45
書かれた数が同じであっても全てのボールは区別することに注意してください。
入力例 3
3 1000000000000000000 2 1000000000 1000000000 2 1000000000 1000000000 2 1000000000 1000000000
出力例 3
0
総積が X になる取り出し方が 1 つも存在しないこともあります。
Score : 300 points
Problem Statement
We have N bags.
Bag i contains L_i balls. The j-th ball (1\leq j\leq L_i) in Bag i has a positive integer a_{i,j} written on it.
We will pick out one ball from each bag.
How many ways are there to pick the balls so that the product of the numbers written on the picked balls is X?
Here, we distinguish all balls, even with the same numbers written on them.
Constraints
- N \geq 2
- L_i \geq 2
- The product of the numbers of balls in the bags is at most 10^5: \displaystyle\prod_{i=1}^{N}L_i \leq 10^5.
- 1 \leq a_{i,j} \leq 10^9
- 1 \leq X \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 a_{1,1} a_{1,2} \ldots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \ldots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \ldots a_{N,L_N}
Output
Print the answer.
Sample Input 1
2 40 3 1 8 4 2 10 5
Sample Output 1
2
When choosing the 3-rd ball in Bag 1 and 1-st ball in Bag 2, we have a_{1,3} \times a_{2,1} = 4 \times 10 = 40.
When choosing the 2-nd ball in Bag 1 and 2-nd ball in Bag 2, we have a_{1,2} \times a_{2,2} = 8 \times 5 = 40.
There are no other ways to make the product 40, so the answer is 2.
Sample Input 2
3 200 3 10 10 10 3 10 10 10 5 2 2 2 2 2
Sample Output 2
45
Note that we distinguish all balls, even with the same numbers written on them.
Sample Input 3
3 1000000000000000000 2 1000000000 1000000000 2 1000000000 1000000000 2 1000000000 1000000000
Sample Output 3
0
There may be no way to make the product X.