Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。
A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。
制約
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
8 0 3 2 6 2 1 0 0
出力例 1
4
非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3 は A に含まれ、4 は A に含まれないので、答えは 4 です。
入力例 2
3 2000 2000 2000
出力例 2
0
Score : 200 points
Problem Statement
You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).
Find the smallest non-negative integer not in (A_1,\ldots,A_N).
Constraints
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
8 0 3 2 6 2 1 0 0
Sample Output 1
4
The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.
Sample Input 2
3 2000 2000 2000
Sample Output 2
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
キーエンスには世界各地に N 個の拠点があり、1 から N までの番号が付けられています。 拠点 i には W_i 人の社員が所属しており、世界標準時で 0 時のとき拠点 i は X_i 時です。
あなたはキーエンス全社で 1 時間の会議を開きたいです。 各社員は、会議の開催時間帯が所属する拠点における 9:00-18:00 の時間帯に完全に含まれる場合にのみ会議に参加できます。 なるべく多くの社員が参加できるように会議の開催時間帯を決めるとき、会議に参加できる社員の数の最大値を求めてください。
制約
- 1\leq N \leq 1000
- 1\leq W_i \leq 10^6
- 0\leq X_i < 24
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N W_1 X_1 W_2 X_2 \vdots W_N X_N
出力
会議に参加できる社員の数の最大値を出力せよ。
入力例 1
3 5 0 3 3 2 18
出力例 1
8
世界標準時で 14:00-15:00 の時間帯に会議を開催することを考えます。
- 拠点 1 における 14:00-15:00 の時間帯に会議が開催されるため、拠点 1 に所属する 5 人の社員は会議に参加できます。
- 拠点 2 における 17:00-18:00 の時間帯に会議が開催されるため、拠点 2 に所属する 3 人の社員は会議に参加できます。
- 拠点 3 における 8:00-9:00 の時間帯に会議が開催されるため、拠点 3 に所属する 2 人の社員は会議に参加できません。
よって、合計で 5+3=8 人の社員が会議に参加できます。 これより多くの社員が参加できるような会議の開催時間帯はありません。
入力例 2
2 1 10 1000000 20
出力例 2
1000000
入力例 3
6 31 3 20 8 11 5 4 3 47 14 1 18
出力例 3
67
Score : 250 points
Problem Statement
Keyence has N bases worldwide, numbered 1 to N. Base i has W_i employees, and at 0 o'clock in Coordinated Universal Time (UTC), it is X_i o'clock at base i.
You want to hold a one-hour meeting across the entire company. Each employee can only participate in the meeting if the meeting time is completely within the 9:00-18:00 time slot at their base. Find the maximum number of employees who can participate when deciding the meeting time to allow as many employees as possible to participate.
Constraints
- 1\leq N \leq 1000
- 1\leq W_i \leq 10^6
- 0\leq X_i < 24
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N W_1 X_1 W_2 X_2 \vdots W_N X_N
Output
Print the maximum number of employees who can participate in the meeting.
Sample Input 1
3 5 0 3 3 2 18
Sample Output 1
8
Consider holding the meeting from 14:00 to 15:00 in UTC.
- The meeting is held from 14:00 to 15:00 at base 1, so the 5 employees at base 1 can participate in the meeting.
- The meeting is held from 17:00 to 18:00 at base 2, so the 3 employees at base 2 can participate in the meeting.
- The meeting is held from 8:00 to 9:00 at base 3, so the 2 employees at base 3 cannot participate in the meeting.
Thus, a total of 5+3=8 employees can participate in the meeting. No meeting time allows more employees to participate.
Sample Input 2
2 1 10 1000000 20
Sample Output 2
1000000
Sample Input 3
6 31 3 20 8 11 5 4 3 47 14 1 18
Sample Output 3
67
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
ある地方に、1 から N の番号がついた N 個の街と、1 から M の番号がついた M 本の道路があります。
i 番目の道路は街 A_i と街 B_i を双方向に結び、長さは C_i です。
好きな街からスタートして同じ街を二度以上通らずに別の街へ移動するときの、通る道路の長さの和としてありえる最大値を求めてください。
制約
- 2 \leq N \leq 10
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1\leq A_i < B_i \leq N
- (A_i,B_i) は相異なる
- 1\leq C_i \leq 10^8
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 C_1 \vdots A_M B_M C_M
出力
答えを出力せよ。
入力例 1
4 4 1 2 1 2 3 10 1 3 100 1 4 1000
出力例 1
1110
4\to 1\to 3\to 2 と移動すると、通る道路の長さの和は 1110 となります。
入力例 2
10 1 5 9 1
出力例 2
1
道路と繋がっていない街が存在するかもしれません。
入力例 3
10 13 1 2 1 1 10 1 2 3 1 3 4 4 4 7 2 4 8 1 5 8 1 5 9 3 6 8 1 6 9 5 7 8 1 7 9 4 9 10 3
出力例 3
20
Score : 300 points
Problem Statement
A region has N towns numbered 1 to N, and M roads numbered 1 to M.
The i-th road connects town A_i and town B_i bidirectionally with length C_i.
Find the maximum possible total length of the roads you traverse when starting from a town of your choice and getting to another town without passing through the same town more than once.
Constraints
- 2 \leq N \leq 10
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i < B_i \leq N
- The pairs (A_i,B_i) are distinct.
- 1\leq C_i \leq 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 C_1 \vdots A_M B_M C_M
Output
Print the answer.
Sample Input 1
4 4 1 2 1 2 3 10 1 3 100 1 4 1000
Sample Output 1
1110
If you travel as 4\to 1\to 3\to 2, the total length of the roads you traverse is 1110.
Sample Input 2
10 1 5 9 1
Sample Output 2
1
There may be a town that is not connected to a road.
Sample Input 3
10 13 1 2 1 1 10 1 2 3 1 3 4 4 4 7 2 4 8 1 5 8 1 5 9 3 6 8 1 6 9 5 7 8 1 7 9 4 9 10 3
Sample Output 3
20
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22
のような指数表記や、 0523
のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22
, for example, or unnecessary leading zeros such as 0523
are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は 2 以上の整数が書かれた N 個のボールを持っており、これらを細長い筒の中に落としていきます。i \, (1 \leq i \leq N) 回目には、a_i が書かれたボールを落とします。
ボールは特殊な材質でできており、筒の中において k \, (k \geq 2) が書かれたボールが k 個連続すると、それら k 個のボールは全て消えてしまいます。
各 i \, (1 \leq i \leq N) について、i 個目のボールを筒の中に落とした後、筒の中に何個のボールがあるか求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 2 \leq a_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、i 個目のボールを筒の中に落とした後、筒の中にあるボールの個数を出力せよ。
入力例 1
5 3 2 3 2 2
出力例 1
1 2 3 4 3
筒の中は次のように変化します。
- 1 個目のボールを落とす。筒の中にあるボールに書かれた整数は 3 である。
- 2 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2 である。
- 3 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3 である。
- 4 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3, 2 である。
- 5 個目のボールを落とす。筒の中にあるボールに書かれた整数は下から順に 3, 2, 3, 2, 2 となるが、2 が書かれたボールが 2 個連続しているのでこれらは消え、下から順に 3, 2, 3 となる。
入力例 2
10 2 3 2 3 3 3 2 3 3 2
出力例 2
1 2 3 4 5 3 2 3 1 0
Score : 400 points
Problem Statement
Takahashi has N balls. Each ball has an integer not less than 2 written on it. He will insert them in a cylinder one by one. The integer written on the i-th ball is a_i.
The balls are made of special material. When k balls with k (k \geq 2) written on them line up in a row, all these k balls will disappear.
For each i (1 \leq i \leq N), find the number of balls after inserting the i-th ball.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 2 \leq a_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 \ldots a_N
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain the number of balls after inserting the i-th ball.
Sample Input 1
5 3 2 3 2 2
Sample Output 1
1 2 3 4 3
The content of the cylinder changes as follows.
- After inserting the 1-st ball, the cylinder contains the ball with 3.
- After inserting the 2-nd ball, the cylinder contains 3, 2 from bottom to top.
- After inserting the 3-rd ball, the cylinder contains 3, 2, 3 from bottom to top.
- After inserting the 4-th ball, the cylinder contains 3, 2, 3, 2 from bottom to top.
- After inserting the 5-th ball, the cylinder momentarily has 3, 2, 3, 2, 2 from bottom to top. The two consecutive balls with 2 disappear, and the cylinder eventually contains 3, 2, 3 from bottom to top.
Sample Input 2
10 2 3 2 3 3 3 2 3 3 2
Sample Output 2
1 2 3 4 5 3 2 3 1 0