実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
横一列に 4 つのマスが並んでいます。
各文字が 0 または 1 である長さ 4 の文字列 S が与えられます。
S の i 文字目が 1 であるとき、左から i 番目のマスには 1 人の人がおり、
S の i 文字目が 0 であるとき、左から i 番目のマスには人がいません。
全ての人が一斉に、1 つ右隣のマスへ移動します。この移動により、もともと右端のマスにいた人は消えます。
移動後の各マスに人がいるかどうかを、S と同様のルールで文字列として出力してください。
制約
- S は
0,1のみからなる長さ 4 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
長さ 4 の文字列であって、移動後、左から i 番目のマスに人がいるならば i 文字目が 1、いないならば 0 であるようなものを出力せよ。
入力例 1
1011
出力例 1
0101
移動により、左から 1 番目のマスにいた人は左から 2 番目のマスに、
左から 3 番目のマスにいた人は左から 4 番目のマスに移動し、
左から 4 番目のマス(右端のマス)にいた人は消えます。
入力例 2
0000
出力例 2
0000
入力例 3
1111
出力例 3
0111
Score : 100 points
Problem Statement
There are 4 squares lined up horizontally.
You are given a string S of length 4 consisting of 0 and 1.
If the i-th character of S is 1, there is a person in the i-th square from the left;
if the i-th character of S is 0, there is no person in the i-th square from the left.
Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.
Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)
Constraints
- S is a string of length 4 consisting of
0and1.
Input
Input is given from Standard Input in the following format:
S
Output
Print a string of length 4 such that the i-th character is 1 if there will be a person in the i-th square from the left after the move, and 0 otherwise.
Sample Input 1
1011
Sample Output 1
0101
After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.
Sample Input 2
0000
Sample Output 2
0000
Sample Input 3
1111
Sample Output 3
0111
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
配信者の高橋君は L 時から R 時に配信をすることにしました。
高橋君には N 人のリスナーがおり、i 人目のリスナーは X_i 時から Y_i 時まで配信を見ることができます。
高橋君の配信を最初から最後まで見ることができるリスナーは何人いますか?
制約
- 1\leq N\leq 100
- 0\leq L\lt R\leq 23
- 0\leq X_i\lt Y_i\leq 23
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L R X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
高橋君の配信を最初から最後まで見ることができるリスナーの数を出力せよ。
入力例 1
5 19 22 17 23 20 23 19 22 0 23 12 20
出力例 1
3
高橋君の配信を最初から最後まで見ることができるのは 1,3,4 人目のリスナーです。
入力例 2
3 12 13 0 1 0 1 0 1
出力例 2
0
高橋君の配信を最初から最後まで見ることができるリスナーはいません。
入力例 3
10 8 14 5 20 14 21 9 21 5 23 8 10 0 14 3 8 2 6 0 16 5 20
出力例 3
5
Score : 100 points
Problem Statement
Streamer Takahashi has decided to stream from L o'clock to R o'clock (using the 24-hour clock).
He has N listeners, and the i-th listener can watch the stream from X_i o'clock to Y_i o'clock.
How many listeners can watch Takahashi's stream from beginning to end?
Constraints
- 1\leq N\leq 100
- 0\leq L\lt R\leq 23
- 0\leq X_i\lt Y_i\leq 23
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L R X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Output the number of listeners who can watch Takahashi's stream from beginning to end.
Sample Input 1
5 19 22 17 23 20 23 19 22 0 23 12 20
Sample Output 1
3
The listeners who can watch Takahashi's stream from beginning to end are the 1st, 3rd, and 4th listeners.
Sample Input 2
3 12 13 0 1 0 1 0 1
Sample Output 2
0
No listeners can watch Takahashi's stream from beginning to end.
Sample Input 3
10 8 14 5 20 14 21 9 21 5 23 8 10 0 14 3 8 2 6 0 16 5 20
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0 か 1 かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0, 1 からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。
各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。
- その回の投票で
0を選択した人が x 人、1を選択した人が y 人いたとします。- x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
- そうでなく x<y である場合、その投票で
0に投票した人のみに 1 点が与えられる。 - そうでない場合、その投票で
1に投票した人のみに 1 点が与えられる。 - なお、 N が奇数であることから x=y となることはないことに留意してください。
M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。
制約
- N は 1 \le N \le 99 を満たす 奇数
- M は 1 \le M \le 100 を満たす整数
- S_i は長さ M の
0,1からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。
入力例 1
3 5 11100 10101 01110
出力例 1
2 3
このケースでは、 3 人が 5 回の投票を行いました。
- 1 回目の投票では人 1 が
1、人 2 が1、人 3 が0に投票しました。よって、人 3 のみが 1 点を得ます。 - 2 回目の投票では人 1 が
1、人 2 が0、人 3 が1に投票しました。よって、人 2 のみが 1 点を得ます。 - 3 回目の投票では人 1 が
1、人 2 が1、人 3 が1に投票しました。よって、全員が 1 点を得ます。 - 4 回目の投票では人 1 が
0、人 2 が0、人 3 が1に投票しました。よって、人 3 のみが 1 点を得ます。 - 5 回目の投票では人 1 が
0、人 2 が1、人 3 が0に投票しました。よって、人 2 のみが 1 点を得ます。
この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。
入力例 2
5 4 0000 0000 0000 0000 0000
出力例 2
1 2 3 4 5
入力例 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
出力例 3
1 2 3
Score : 200 points
Problem Statement
People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0 or 1.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0 and 1, where the j-th character of S_i represents person i's vote content for the j-th vote.
In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:
- Suppose x people chose
0and y people chose1in that vote.- If x=0 or y=0, everyone receives 1 point for that vote.
- Otherwise, if x<y, only people who voted
0in that vote receive 1 point. - Otherwise, only people who voted
1in that vote receive 1 point. - Note that since N is odd, x=y never occurs.
After finishing M votes, find all people who have the highest total score from those votes.
Constraints
- N is an odd number satisfying 1 \le N \le 99.
- M is an integer satisfying 1 \le M \le 100.
- S_i is a string of length M consisting of
0and1.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Output all person numbers with the highest score in ascending order of person number, separated by spaces.
Sample Input 1
3 5 11100 10101 01110
Sample Output 1
2 3
In this case, three people conducted five votes.
- In the 1st vote, person 1 voted
1, person 2 voted1, person 3 voted0. Thus, only person 3 receives 1 point. - In the 2nd vote, person 1 voted
1, person 2 voted0, person 3 voted1. Thus, only person 2 receives 1 point. - In the 3rd vote, person 1 voted
1, person 2 voted1, person 3 voted1. Thus, everyone receives 1 point. - In the 4th vote, person 1 voted
0, person 2 voted0, person 3 voted1. Thus, only person 3 receives 1 point. - In the 5th vote, person 1 voted
0, person 2 voted1, person 3 voted0. Thus, only person 2 receives 1 point.
As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.
Sample Input 2
5 4 0000 0000 0000 0000 0000
Sample Output 2
1 2 3 4 5
Sample Input 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
Sample Output 3
1 2 3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1, \dots, N の番号が付けられており、i \, (1 \leq i \leq M) 番目の辺は頂点 U_i と頂点 V_i を結んでいます。
以下の条件を全て満たす整数 a, b, c の組の総数を求めてください。
- 1 \leq a \lt b \lt c \leq N
- 頂点 a と頂点 b を結ぶ辺が存在する。
- 頂点 b と頂点 c を結ぶ辺が存在する。
- 頂点 c と頂点 a を結ぶ辺が存在する。
制約
- 3 \leq N \leq 100
- 1 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
- (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 \vdots U_M V_M
出力
答えを出力せよ。
入力例 1
5 6 1 5 4 5 2 3 1 4 3 5 2 5
出力例 1
2
(a, b, c) = (1, 4, 5), (2, 3, 5) が条件を満たします。
入力例 2
3 1 1 2
出力例 2
0
入力例 3
7 10 1 7 5 7 2 5 3 6 4 7 1 5 2 4 1 3 1 6 2 7
出力例 3
4
Score : 200 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N, and the i-th (1 \leq i \leq M) edge connects Vertex U_i and Vertex V_i.
Find the number of tuples of integers a, b, c that satisfy all of the following conditions:
- 1 \leq a \lt b \lt c \leq N
- There is an edge connecting Vertex a and Vertex b.
- There is an edge connecting Vertex b and Vertex c.
- There is an edge connecting Vertex c and Vertex a.
Constraints
- 3 \leq N \leq 100
- 1 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
- (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M U_1 V_1 \vdots U_M V_M
Output
Print the answer.
Sample Input 1
5 6 1 5 4 5 2 3 1 4 3 5 2 5
Sample Output 1
2
(a, b, c) = (1, 4, 5), (2, 3, 5) satisfy the conditions.
Sample Input 2
3 1 1 2
Sample Output 2
0
Sample Input 3
7 10 1 7 5 7 2 5 3 6 4 7 1 5 2 4 1 3 1 6 2 7
Sample Output 3
4
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
長さ N の正整数列 A=(A_1,A_2,\dots,A_N) および正整数 K が与えられます。
1 以上 K 以下の整数のうち、A の中に一度も現れないものの総和を求めてください。
制約
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 5 1 6 3 1
出力例 1
11
1 以上 5 以下の整数のうち、A の中に一度も現れないものは 2,4,5 の 3 つです。
よって、それらの総和である 2+4+5=11 を出力します。
入力例 2
1 3 346
出力例 2
6
入力例 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
出力例 3
12523196466007058
Score: 250 points
Problem Statement
You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer K.
Find the sum of the integers between 1 and K, inclusive, that do not appear in the sequence A.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 5 1 6 3 1
Sample Output 1
11
Among the integers between 1 and 5, three numbers, 2, 4, and 5, do not appear in A.
Thus, print their sum: 2+4+5=11.
Sample Input 2
1 3 346
Sample Output 2
6
Sample Input 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
Sample Output 3
12523196466007058