Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
入学試験の受験者が N 人います。
試験の結果、 i 番の受験生は数学で A_i 点、英語で B_i 点を取りました。
試験の合格者は次のように決められます。
- 数学の点が高い方から X 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、英語の点が高い方から Y 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、数学と英語の合計点が高い方から Z 人を合格とする。
- ここまでで合格となっていない受験者は、不合格とする。
ただし、 1. から 3. までのどの段階についても、同点であった場合は受験生の番号の小さい方を優先します。入出力例も参照してください。
以上の手順で合格者を決める時、合格となった受験生の番号を小さい方から順に改行区切りで出力してください。
制約
- 入力は全て整数
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
合格となった受験生の番号を小さい方から順に改行区切りで出力せよ。
入力例 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
出力例 1
1 4 5
- まず、数学の点が高い方から 1 人が合格となります。
- 数学の最高点は 80 点で 1 番の受験生と 3 番の受験生が並んでいますが、受験生の番号が小さい方が優先され 1 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者のうち、英語の点が高い方から 0 人が合格となります。
- 明らかに、ここで合格者が増えることはありません。
- 次に、まだ合格となっていない受験者のうち、数学と英語の合計点が高い方から 2 人が合格となります。
- まず、まだ合格となっていない受験者の中で、合計点が 160 点と最も高い 5 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者の中で、合計点が 150 点の 4 番の受験生と 6 番の受験生が並んでいます。受験生の番号の小さい方が優先され、 4 番の受験生が合格となります。
以上より、合格となる受験生の番号は 1,4,5 なので、小さい方から出力してください。
入力例 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
出力例 2
1 2 3 4 5
全員が合格となることもあります。
入力例 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
出力例 3
2 4 5 6 7 8 11 14 15
Score : 200 points
Problem Statement
N examinees took an entrance exam.
The examinee numbered i scored A_i points in math and B_i points in English.
The admissions are determined as follows.
- X examinees with the highest math scores are admitted.
- Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted.
- Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted.
- Those examinees who are not admitted yet are rejected.
Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output.
Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.
Constraints
- All values in input are integers.
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
Input
Input is given from Standard Input in the following format:
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the examinees' number of the admitted examinees in ascending order, separated by newlines.
Sample Input 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
Sample Output 1
1 4 5
- First, 1 examinee with the highest math score is admitted.
- Examinee 1 is tied with Examinee 3, scoring the highest 80 points in math, and the tie is broken by the examinees' numbers, so Examinee 1 is admitted.
- Then, among the examinees who are not admitted yet, 0 examinees with the highest English scores are admitted.
- Obviously, it does not affect the admissions.
- Then, among the examinees who are not admitted yet, 2 examinees with the highest total scores in math and English are admitted.
- First, among the examinees who are not admitted yet, Examinee 5 is admitted, scoring the highest total score of 160 points.
- Next, among the examinees who are not admitted yet, Examinee 4 is tied with Examinee 6, scoring a total score of 150 points. The tie is broken by the examinees' numbers, and Examinee 4 is admitted.
Therefore, the examinees' numbers of the admitted examinees are 1, 4, and 5. Print them in ascending order.
Sample Input 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
Sample Output 2
1 2 3 4 5
All examinees may be admitted.
Sample Input 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
Sample Output 3
2 4 5 6 7 8 11 14 15
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 N,M と長さ N の数字列 S 、長さ M の数字列 T が与えられます。ここで、数字列とは 0 から 9 までの数字のみから構成される文字列のことを表します。
あなたは以下の操作を 0 回以上好きな回数行うことができます:
- T から 1 文字選び、選んだ数字を 1 増やす。ただし、選んだ数字が
9である場合は0にする。
T を S の部分文字列(連続する部分列)にするために必要な操作回数の最小値を求めてください。
制約
- 1\le M\le N\le 100
- N,M は整数
- S は長さ N の数字列
- T は長さ M の数字列
入力
入力は以下の形式で標準入力から与えられる。
N M S T
出力
T を S の部分文字列にするために必要な操作回数の最小値を出力せよ。
入力例 1
4 2 2025 91
出力例 1
2
以下のように 2 回操作することで T を S の部分文字列にすることができます。
- T の 2 文字目に対して操作する。 T=
91から T=92になる。 - T の 1 文字目に対して操作する。 T=
92から T=02になる。
02 は S の 2 文字目から 3 文字目までの部分文字列となっています。
2 回未満の操作で T を S の部分文字列にすることはできないため、 2 を出力してください。
入力例 2
3 2 438 38
出力例 2
0
はじめから 38 は 438 の部分文字列です。したがって、0 を出力してください。
入力例 3
5 5 00000 11111
出力例 3
45
入力例 4
8 3 20251227 438
出力例 4
13
Score : 200 points
Problem Statement
You are given integers N and M, a digit string S of length N, and a digit string T of length M. Here, a digit string is a string consisting of digits from 0 to 9.
You can perform the following operation zero or more times:
- Choose one character from T and increase the chosen digit by 1. However, if the chosen digit is
9, change it to0.
Find the minimum number of operations required to make T a substring (contiguous subsequence) of S.
Constraints
- 1\le M\le N\le 100
- N and M are integers.
- S is a digit string of length N.
- T is a digit string of length M.
Input
The input is given from Standard Input in the following format:
N M S T
Output
Output the minimum number of operations required to make T a substring of S.
Sample Input 1
4 2 2025 91
Sample Output 1
2
You can make T a substring of S with two operations as follows:
- Perform the operation on the 2nd character of T. T=
91becomes T=92. - Perform the operation on the 1st character of T. T=
92becomes T=02.
02 is a substring from the 2nd character to the 3rd character of S.
It is impossible to make T a substring of S with less than two operations, so output 2.
Sample Input 2
3 2 438 38
Sample Output 2
0
38 is a substring of 438 from the beginning. Thus, output 0.
Sample Input 3
5 5 00000 11111
Sample Output 3
45
Sample Input 4
8 3 20251227 438
Sample Output 4
13
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
非負整数 N が与えられるので、以下の条件を満たす非負整数 x を昇順に全て出力してください。
- x を 2 進数として表記した時に 1 となる位の集合が、 N を 2 進数として表記した時に 1 となる位の集合の部分集合となる。
- すなわち、全ての非負整数 k について、「 x の 2^k の位が 1 ならば、 N の 2^k の位は 1 」が成り立つ。
制約
- N は整数
- 0 \le N < 2^{60}
- N を 2 進数として表記した時、 1 となる位は 15 個以下である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを 1 行に 1 つずつ、10 進法の整数として昇順に出力せよ。
入力例 1
11
出力例 1
0 1 2 3 8 9 10 11
N = 11_{(10)} を 2 進数で表記すると、 1011_{(2)} となります。
条件を満たす非負整数 x は以下の通りです。
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
入力例 2
0
出力例 2
0
入力例 3
576461302059761664
出力例 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
入力は 32bit 符号付き整数に収まらない可能性があります。
Score : 300 points
Problem Statement
You are given a non-negative integer N. Print all non-negative integers x that satisfy the following condition in ascending order.
- The set of the digit positions containing 1 in the binary representation of x is a subset of the set of the digit positions containing 1 in the binary representation of N.
- That is, the following holds for every non-negative integer k: if the digit in the "2^ks" place of x is 1, the digit in the 2^ks place of N is 1.
Constraints
- N is an integer.
- 0 \le N < 2^{60}
- In the binary representation of N, at most 15 digit positions contain 1.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer as decimal integers in ascending order, each in its own line.
Sample Input 1
11
Sample Output 1
0 1 2 3 8 9 10 11
The binary representation of N = 11_{(10)} is 1011_{(2)}.
The non-negative integers x that satisfy the condition are:
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
Sample Input 2
0
Sample Output 2
0
Sample Input 3
576461302059761664
Sample Output 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
The input may not fit into a 32-bit signed integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
N 個の整数の組 (L_1,R_1),(L_2,R_2),\ldots,(L_N,R_N) が与えられます。
以下の条件を満たす長さ N の整数列 X=(X_1,X_2,\ldots,X_N) が存在するか判定し、存在するならば一つ出力してください。
- 各 i=1,2,\ldots,N に対して L_i\leq X_i\leq R_i
- \displaystyle \sum_{i=1}^N X_i=0
制約
- 1\leq N\leq 2\times 10^5
- -10^9\leq L_i\leq R_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 R_1 L_2 R_2 \vdots L_N R_N
出力
存在しない場合は No を出力せよ。存在する場合は条件を満たす整数列 X を以下の形式で出力せよ。
Yes X_1 X_2 \ldots X_N
答えが複数存在する場合、どれを出力しても正解とみなされる。
入力例 1
3 3 5 -4 1 -2 3
出力例 1
Yes 4 -3 -1
数列 X=(4,-3,-1) は問題の条件をすべて満たします。ほかにも (3,-3,0) や (5,-4,-1) などが条件を満たします。
入力例 2
3 1 2 1 2 1 2
出力例 2
No
条件を満たす整数列 X は存在しません。
入力例 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
出力例 3
Yes -66 -57 31 -6 89 9
Score : 350 points
Problem Statement
You are given N pairs of integers (L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N).
Determine whether there exists a sequence of N integers X = (X_1, X_2, \ldots, X_N) that satisfies the following conditions, and print one such sequence if it exists.
- L_i \leq X_i \leq R_i for each i = 1, 2, \ldots, N.
- \displaystyle \sum_{i=1}^N X_i = 0.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq L_i \leq R_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 R_1 L_2 R_2 \vdots L_N R_N
Output
If no solution exists, print No. Otherwise, print an integer sequence X that satisfies the conditions in the following format:
Yes X_1 X_2 \ldots X_N
If multiple solutions exist, any of them will be considered correct.
Sample Input 1
3 3 5 -4 1 -2 3
Sample Output 1
Yes 4 -3 -1
The sequence X = (4, -3, -1) satisfies all the conditions. Other valid sequences include (3, -3, 0) and (5, -4, -1).
Sample Input 2
3 1 2 1 2 1 2
Sample Output 2
No
No sequence X satisfies the conditions.
Sample Input 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
Sample Output 3
Yes -66 -57 31 -6 89 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。
- 1\leq i \lt j \lt k \leq N
- A_i,A_j,A_k は相異なる
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 4 1
出力例 1
2
条件を満たす整数の組 (i,j,k) は (1,2,3),(1,3,4) の 2 つです。
入力例 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
出力例 2
120
入力例 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
出力例 3
355
Score : 400 points
Problem Statement
You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.
- 1\leq i \lt j \lt k \leq N
- A_i, A_j, and A_k are distinct.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 3 1 4 1
Sample Output 1
2
The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).
Sample Input 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
Sample Output 2
120
Sample Input 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
Sample Output 3
355