Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?
制約
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S, T は整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。
入力例 1
1 0
出力例 1
4
条件を満たす非負整数の組 (a,b,c) は (0,0,0), (0,0,1), (0,1,0), (1,0,0) の 4 つです。
入力例 2
2 5
出力例 2
10
入力例 3
10 10
出力例 3
213
入力例 4
30 100
出力例 4
2471
Score : 200 points
Problem Statement
How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?
Constraints
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S and T are integers.
Input
Input is given from Standard Input in the following format:
S T
Output
Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.
Sample Input 1
1 0
Sample Output 1
4
The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.
Sample Input 2
2 5
Sample Output 2
10
Sample Input 3
10 10
Sample Output 3
213
Sample Input 4
30 100
Sample Output 4
2471
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個のボールが左右一列に並んでいます。初め、左から i \, (1 \leq i \leq N) 番目のボールには整数 i が書かれています。
高橋君は Q 回の操作を行いました。 i \, (1 \leq i \leq Q) 回目に行われた操作は次のようなものです。
- 整数 x_i が書かれているボールをその右隣のボールと入れ替える。ただし、整数 x_i が書かれているボールが元々右端にあった場合、代わりに左隣のボールと入れ替える。
操作後において左から i \, (1 \leq i \leq N) 番目のボールに書かれている整数を a_i とします。 a_1,\ldots,a_N を求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q x_1 \vdots x_Q
出力
a_1,\ldots,a_N を空白区切りで出力せよ。
入力例 1
5 5 1 2 3 4 5
出力例 1
1 2 3 5 4
操作は以下のように行われます。
- 1 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 2,1,3,4,5 となる。
- 2 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 3 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,4,3,5 となる。
- 4 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 5 と書かれたボールは右端にあるので左隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,5,4 となる。
入力例 2
7 7 7 7 7 7 7 7 7
出力例 2
1 2 3 4 5 7 6
入力例 3
10 6 1 5 2 9 6 6
出力例 3
1 2 3 4 5 7 6 8 10 9
Score : 300 points
Problem Statement
N balls are lined up in a row from left to right. Initially, the i-th (1 \leq i \leq N) ball from the left has an integer i written on it.
Takahashi has performed Q operations. The i-th (1 \leq i \leq Q) operation was as follows.
- Swap the ball with the integer x_i written on it with the next ball to the right. If the ball with the integer x_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.
Let a_i be the integer written on the i-th (1 \leq i \leq N) ball after the operations. Find a_1,\ldots,a_N.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q x_1 \vdots x_Q
Output
Print a_1,\ldots,a_N, with spaces in between.
Sample Input 1
5 5 1 2 3 4 5
Sample Output 1
1 2 3 5 4
The operations are performed as follows.
- Swap the ball with 1 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,5 written on them, from left to right.
- Swap the ball with 2 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 3 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,5 written on them, from left to right.
- Swap the ball with 4 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 5 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,4 written on them, from left to right.
Sample Input 2
7 7 7 7 7 7 7 7 7
Sample Output 2
1 2 3 4 5 7 6
Sample Input 3
10 6 1 5 2 9 6 6
Sample Output 3
1 2 3 4 5 7 6 8 10 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数の多重集合 S があります。はじめ S は空です。
Q 個のクエリが与えられるので順に処理してください。 クエリは次の 3 種類のいずれかです。
-
1 x: S に x を 1 個追加する。 -
2 x c: S から x を \mathrm{min}(c, (S に含まれる x の個数 )) 個削除する。 -
3: (S の最大値 )- (S の最小値 ) を出力する。このクエリを処理するとき、 S が空でないことが保証される。
制約
- 1 \leq Q \leq 2\times 10^5
- 0 \leq x \leq 10^9
- 1 \leq c \leq Q
3のクエリを処理するとき、S は空でない。- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
i 番目のクエリを表す \mathrm{query}_i は以下の 3 種類のいずれかである。
1 x
2 x c
3
出力
3 のクエリに対する答えを順に改行区切りで出力せよ。
入力例 1
8 1 3 1 2 3 1 2 1 7 3 2 2 3 3
出力例 1
1 5 4
多重集合 S は以下のように変化します。
- 1 番目のクエリ : S に 3 を追加する。S は \lbrace3 \rbrace となる。
- 2 番目のクエリ : S に 2 を追加する。S は \lbrace2, 3\rbrace となる。
- 3 番目のクエリ : S = \lbrace 2, 3\rbrace の最大値は 3 、最小値は 2 なので、 3-2=1 を出力する。
- 4 番目のクエリ : S に 2 を追加する。S は \lbrace2,2,3 \rbrace となる。
- 5 番目のクエリ : S に 7 を追加する。S は \lbrace2, 2,3, 7\rbrace となる。
- 6 番目のクエリ : S = \lbrace2,2,3, 7\rbrace の最大値は 7 、最小値は 2 なので、 7-2=5 を出力する。
- 7 番目のクエリ : S に含まれる 2 の個数は 2 個なので、 \mathrm{min(2,3)} = 2 個の 2 を S から削除する。S は \lbrace3, 7\rbrace となる。
- 8 番目のクエリ : S = \lbrace3, 7\rbrace の最大値は 7 、最小値は 3 なので、 7-3=4 を出力する。
入力例 2
4 1 10000 1 1000 2 100 3 1 10
出力例 2
クエリ 3 が含まれない場合、何も出力してはいけません。
Score : 300 points
Problem Statement
We have a multiset of integers S, which is initially empty.
Given Q queries, process them in order. Each query is of one of the following types.
-
1 x: Insert an x into S. -
2 x c: Remove an x from S m times, where m = \mathrm{min}(c,( the number of x's contained in S)). -
3: Print ( maximum value of S)-( minimum value of S). It is guaranteed that S is not empty when this query is given.
Constraints
- 1 \leq Q \leq 2\times 10^5
- 0 \leq x \leq 10^9
- 1 \leq c \leq Q
- When a query of type
3is given, S is not empty. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
\mathrm{query}_i, which denotes the i-th query, is in one of the following formats:
1 x
2 x c
3
Output
Print the answers for the queries of type 3 in the given order, separated by newlines.
Sample Input 1
8 1 3 1 2 3 1 2 1 7 3 2 2 3 3
Sample Output 1
1 5 4
The multiset S transitions as follows.
- 1-st query: insert 3 into S. S is now \lbrace 3 \rbrace.
- 2-nd query: insert 2 into S. S is now \lbrace 2, 3 \rbrace.
- 3-rd query: the maximum value of S = \lbrace 2, 3\rbrace is 3 and its minimum value is 2, so print 3-2=1.
- 4-th query: insert 2 into S. S is now \lbrace 2,2,3 \rbrace.
- 5-th query: insert 7 into S. S is now \lbrace 2, 2,3, 7\rbrace.
- 6-th query: the maximum value of S = \lbrace 2,2,3, 7\rbrace is 7 and its minimum value is 2, so print 7-2=5.
- 7-th query: since there are two 2's in S and \mathrm{min(2,3)} = 2, remove 2 from S twice. S is now \lbrace 3, 7\rbrace.
- 8-th query: the maximum value of S = \lbrace 3, 7\rbrace is 7 and its minimum value is 3, so print 7-3=4.
Sample Input 2
4 1 10000 1 1000 2 100 3 1 10
Sample Output 2
If the given queries do not contain that of type 3, nothing should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
整数 W が与えられます。
あなたは以下の条件をすべて満たすようにいくつかのおもりを用意することにしました。
- おもりの個数は 1 個以上 300 個以下である。
- おもりの重さは 10^6 以下の正整数である。
- 1 以上 W 以下のすべての正整数は 良い整数 である。ここで、以下の条件を満たす正整数 n を良い整数と呼ぶ。
- 用意したおもりのうち \bf{3} 個以下 の異なるおもりを自由に選んで、選んだおもりの重さの和を n にすることができる。
条件を満たすようなおもりの組を 1 つ出力してください。
制約
- 1 \leq W \leq 10^6
- W は整数
入力
入力は以下の形式で標準入力から与えられる。
W
出力
N をおもりの個数、A_i を i 番目のおもりの重さとして、以下の形式で出力せよ。答えが複数存在する場合、どれを出力しても正解とみなされる。
N A_1 A_2 \dots A_N
ただし、N および A_1,A_2,\dots,A_N は以下の条件を満たす必要がある。
- 1 \leq N \leq 300
- 1 \leq A_i \leq 10^6
入力例 1
6
出力例 1
3 1 2 3
上の出力は重さ 1 のおもり、重さ 2 のおもり、重さ 3 のおもりの 3 個のおもりを用意しています。
この出力は条件を満たしています。特に 3 番目の条件について、以下のようにおもりを選ぶことで 1 以上 W 以下の整数すべてが良い整数であることが確認できます。
- 1 番目のおもりのみを選ぶと、重さの和は 1 になる。
- 2 番目のおもりのみを選ぶと、重さの和は 2 になる。
- 3 番目のおもりのみを選ぶと、重さの和は 3 になる。
- 1 番目と 3 番目のおもりを選ぶと、重さの和は 4 になる。
- 2 番目と 3 番目のおもりを選ぶと、重さの和は 5 になる。
- 1 番目、2 番目と 3 番目のおもりを選ぶと、重さの和は 6 になる。
入力例 2
12
出力例 2
6 2 5 1 2 5 1
同じ重さのおもりを 2 個以上用意しても良いです。
Score : 400 points
Problem Statement
You are given an integer W.
You are going to prepare some weights so that all of the conditions below are satisfied.
- The number of weights is between 1 and 300, inclusive.
- Each weight has a mass of positive integer not exceeding 10^6.
- Every integer between 1 and W, inclusive, is a good integer. Here, a positive integer n is said to be a good integer if the following condition is satisfied:
- We can choose at most 3 different weights from the prepared weights with a total mass of n.
Print a combination of weights that satisfies the conditions.
Constraints
- 1 \leq W \leq 10^6
- W is an integer.
Input
Input is given from Standard Input in the following format:
W
Output
Print in the following format, where N is the number of weights and A_i is the mass of the i-th weight. If multiple solutions exist, printing any of them is accepted.
N A_1 A_2 \dots A_N
Here, N and A_1,A_2,\dots,A_N should satisfy the following conditions:
- 1 \leq N \leq 300
- 1 \leq A_i \leq 10^6
Sample Input 1
6
Sample Output 1
3 1 2 3
In the output above, 3 weights with masses 1, 2, and 3 are prepared.
This output satisfies the conditions. Especially, regarding the 3-rd condition, we can confirm that every integer between 1 and W, inclusive, is a good integer.
- If we choose only the 1-st weight, it has a total mass of 1.
- If we choose only the 2-nd weight, it has a total mass of 2.
- If we choose only the 3-rd weight, it has a total mass of 3.
- If we choose the 1-st and the 3-rd weights, they have a total mass of 4.
- If we choose the 2-nd and the 3-rd weights, they have a total mass of 5.
- If we choose the 1-st, the 2-nd, and the 3-rd weights, they have a total mass of 6.
Sample Input 2
12
Sample Output 2
6 2 5 1 2 5 1
You may prepare multiple weights with the same mass.