Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
AtCoder Beginner Contest は、今回で 214 回目の開催となりました。
今までの AtCoder Beginner Contest において、出題される問題数は次のように変化しました。
- 1 回目から 125 回目までは 4 問
- 126 回目から 211 回目までは 6 問
- 212 回目から 214 回目までは 8 問
N 回目の AtCoder Beginner Contest において出題された問題数を求めてください。
制約
- 1 \leq N \leq 214
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
214
出力例 1
8
入力例 2
1
出力例 2
4
入力例 3
126
出力例 3
6
Score : 100 points
Problem Statement
This is the 214-th AtCoder Beginner Contest (ABC).
The ABCs so far have had the following number of problems.
- The 1-st through 125-th ABCs had 4 problems each.
- The 126-th through 211-th ABCs had 6 problems each.
- The 212-th through 214-th ABCs have 8 problems each.
Find the number of problems in the N-th ABC.
Constraints
- 1 \leq N \leq 214
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
214
Sample Output 1
8
Sample Input 2
1
Sample Output 2
4
Sample Input 3
126
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 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 MB
配点 : 300 点
問題文
N 人のすぬけ君が円周上に並んでおり、反時計回りに 1,2,...,N の番号がついています。
i\, (1 \leq i \leq N) 番目のすぬけ君は時刻 t に宝石をもらうと S_i 単位時間後、すなわち時刻 t+S_i にその宝石を (i+1) 番目のすぬけ君に渡します。ただし、(N+1) 番目のすぬけ君とは 1 番目のすぬけ君のことを指すとします。
また、高橋君は時刻 T_i に i 番目のすぬけ君に宝石を渡します。
全ての i\, (1 \leq i \leq N) について、i 番目のすぬけ君が初めて宝石をもらう時刻を求めてください。なお、宝石の受け渡しにかかる時間は無視できるものとします。
制約
- 1 \leq N \leq 200000
- 1 \leq S_i,T_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \ldots S_N T_1 T_2 \ldots T_N
出力
N 行出力せよ。i\, (1 \leq i \leq N) 行目には、i 番目のすぬけ君が初めて宝石をもらう時刻を出力すること。
入力例 1
3 4 1 5 3 10 100
出力例 1
3 7 8
時刻 13 までのすぬけ君と高橋君の行動を時系列順に並べます。
時刻 3 : 高橋君が 1 番目のすぬけ君に宝石を渡します。
時刻 7 : 1 番目のすぬけ君が 2 番目のすぬけ君に宝石を渡します。
時刻 8 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。
時刻 10 : 高橋君が 2 番目のすぬけ君に宝石を渡します。
時刻 11 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。
時刻 13 : 3 番目のすぬけ君が 1 番目のすぬけ君に宝石を渡します。
時刻 14 以降も彼らは宝石の受け渡しを行いますが、答えには影響しません。
入力例 2
4 100 100 100 100 1 1 1 1
出力例 2
1 1 1 1
S_i や T_i が相異なるとは限らないことに注意してください。
入力例 3
4 1 2 3 4 1 2 4 7
出力例 3
1 2 4 7
あるすぬけくんが同時刻に複数の宝石の受け渡しをする可能性があること、特に高橋くんとすぬけくんの両方から同時に宝石を貰う可能性があることに注意してください。
入力例 4
8 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27
出力例 4
50 22 63 28 44 60 64 27
Score : 300 points
Problem Statement
There are N creatures standing in a circle, called Snuke 1, 2, ..., N in counter-clockwise order.
When Snuke i (1 \leq i \leq N) receives a gem at time t, S_i units of time later, it will hand that gem to Snuke i+1 at time t+S_i. Here, Snuke N+1 is Snuke 1.
Additionally, Takahashi will hand a gem to Snuke i at time T_i.
For each i (1 \leq i \leq N), find the time when Snuke i receives a gem for the first time. Assume that it takes a negligible time to hand a gem.
Constraints
- 1 \leq N \leq 200000
- 1 \leq S_i,T_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \ldots S_N T_1 T_2 \ldots T_N
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain the time when Snuke i receives a gem for the first time.
Sample Input 1
3 4 1 5 3 10 100
Sample Output 1
3 7 8
We will list the three Snuke's and Takahashi's actions up to time 13 in chronological order.
Time 3: Takahashi hands a gem to Snuke 1.
Time 7: Snuke 1 hands a gem to Snuke 2.
Time 8: Snuke 2 hands a gem to Snuke 3.
Time 10: Takahashi hands a gem to Snuke 2.
Time 11: Snuke 2 hands a gem to Snuke 3.
Time 13: Snuke 3 hands a gem to Snuke 1.
After that, they will continue handing gems, though it will be irrelevant to the answer.
Sample Input 2
4 100 100 100 100 1 1 1 1
Sample Output 2
1 1 1 1
Note that the values S_i and T_i may not be distinct.
Sample Input 3
4 1 2 3 4 1 2 4 7
Sample Output 3
1 2 4 7
Note that a Snuke may perform multiple transactions simultaneously. Particularly, a Snuke may receive gems simultaneously from Takahashi and another Snuke.
Sample Input 4
8 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27
Sample Output 4
50 22 63 28 44 60 64 27
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
N 頂点の木があり、頂点は 1, 2, \dots, N と番号付けられています。
i \, (1 \leq i \leq N - 1) 番目の辺は頂点 u_i と頂点 v_i を結び、重みは w_i です。
異なる頂点 u, v に対し、頂点 u から頂点 v までの最短パスに含まれる辺の重みの最大値を f(u, v) とおきます。
\displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j) を求めてください。
制約
- 2 \leq N \leq 10^5
- 1 \leq u_i, v_i \leq N
- 1 \leq w_i \leq 10^7
- 与えられるグラフは木である。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N u_1 v_1 w_1 \vdots u_{N - 1} v_{N - 1} w_{N - 1}
出力
答えを出力せよ。
入力例 1
3 1 2 10 2 3 20
出力例 1
50
f(1, 2) = 10, f(2, 3) = 20, f(1, 3) = 20 であるので、これらの和である 50 を出力します。
入力例 2
5 1 2 1 2 3 2 4 2 5 3 5 14
出力例 2
76
Score : 400 points
Problem Statement
We have a tree with N vertices numbered 1, 2, \dots, N.
The i-th edge (1 \leq i \leq N - 1) connects Vertex u_i and Vertex v_i and has a weight w_i.
For different vertices u and v, let f(u, v) be the greatest weight of an edge contained in the shortest path from Vertex u to Vertex v.
Find \displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j).
Constraints
- 2 \leq N \leq 10^5
- 1 \leq u_i, v_i \leq N
- 1 \leq w_i \leq 10^7
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N u_1 v_1 w_1 \vdots u_{N - 1} v_{N - 1} w_{N - 1}
Output
Print the answer.
Sample Input 1
3 1 2 10 2 3 20
Sample Output 1
50
We have f(1, 2) = 10, f(2, 3) = 20, and f(1, 3) = 20, so we should print their sum, or 50.
Sample Input 2
5 1 2 1 2 3 2 4 2 5 3 5 14
Sample Output 2
76
Time Limit: 3 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
T 個のテストケースについて、以下の問題を解いてください。
1,2,\dots,10^9 の番号がついた 10^9 個の箱と、 1,2,\dots,N の番号がついた N 個のボールがあります。
それぞれの箱に入れることのできるボールの個数は多くとも 1 個です。
以下の条件を満たすように、 N 個のボールを全て箱に入れることができるか判定してください。
- 全ての 1 以上 N 以下の整数 i について、番号 i のボールが L_i 以上 R_i 以下の番号がついた箱に入っている。
制約
- 1 \le T \le 2 \times 10^5
- 1 \le N \le 2 \times 10^5
- 1 \le L_i \le R_i \le 10^9
- 1 つの入力に含まれるテストケースについて、それらの N の総和は 2 \times 10^5 を超えない。
入力
入力は標準入力から与えられる。入力の 1 行目は以下の形式である。
T
その後、 T 個のテストケースが続く。各テストケースは以下の形式で与えられる。
N L_1 R_1 L_2 R_2 \dots L_N R_N
出力
出力は T 行からなる。
i(1 \le i \le T) 行目には、 i 番目に入力されたテストケースについて、問題文中の条件を満たすように N 個のボールを全て箱に入れることができるなら Yes
、そうでないなら No
と出力せよ。
なお、正誤判定器は英大文字と英小文字を区別せず、どちらも受理する。
入力例 1
2 3 1 2 2 3 3 3 5 1 2 2 3 3 3 1 3 999999999 1000000000
出力例 1
Yes No
この入力には 2 つのテストケースが含まれます。
-
1 つ目のテストケースについて、以下のようにボールを箱に入れると、問題文中の条件を満たすように 3 個のボールを全て箱に入れることができるので、
Yes
と出力します。- ボール 1 を箱 1 に入れる。
- ボール 2 を箱 2 に入れる。
- ボール 3 を箱 3 に入れる。
-
2 つ目のテストケースについて、問題文中の条件を満たすように 5 個のボールを全て箱に入れることはできないので、
No
と出力します。
Score : 500 points
Problem Statement
Solve the following problem for T test cases.
There are 10^9 boxes numbered 1,2,\dots,10^9 and N balls numbered 1,2,\dots,N.
Each box can contain at most one ball.
Determine whether it is possible to put all N balls in the boxes so that the following condition will be satisfied.
- For each integer i from 1 through N, the ball numbered i is in a box numbered between L_i and R_i (inclusive).
Constraints
- 1 \le T \le 2 \times 10^5
- 1 \le N \le 2 \times 10^5
- 1 \le L_i \le R_i \le 10^9
- The sum of N across the test cases in one input is at most 2 \times 10^5.
Input
Input is given from Standard Input. The first line is in the following format:
T
Then, T test cases follows, each of which is in the following format:
N L_1 R_1 L_2 R_2 \dots L_N R_N
Output
Your output should have T lines.
In the i-th (1 \le i \le T) line, print Yes
if it is possible to put all N balls in the boxes so that the condition will be satisfied in the i-th test case in the input, and printNo
otherwise.
The checker is case-insensitive; it will accept both uppercase and lowercase letters.
Sample Input 1
2 3 1 2 2 3 3 3 5 1 2 2 3 3 3 1 3 999999999 1000000000
Sample Output 1
Yes No
This input contains two test cases.
-
In the 1-st test case, the following way to put the three balls would satisfy the condition, so we should print
Yes
.- Put Ball 1 in Box 1.
- Put Ball 2 in Box 2.
- Put Ball 3 in Box 3.
-
In the 2-nd test case, there is no way to put the five balls to satisfy the condition, so we should print
No
.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
文字列 S が与えられます。高橋君はこの文字列から以下の手順にしたがって新しい文字列 T を作ります。
- まず、S の文字のうちの一つ以上に印をつける。ただし、印をつけた文字どうしが隣り合ってはならない。
- 次に、印がついていない文字を全て削除する。
- 最後に、残った文字列を T とする。ただし、この時に文字を並び替えてはならない。
T としてありうる文字列は何種類ありますか? (10^9 + 7) で割ったあまりを求めてください。
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
T としてありうる文字列の種類数を (10^9 + 7) で割ったあまりを出力せよ。
入力例 1
abc
出力例 1
4
T としてありうるものは a
、 b
、 c
、 ac
の 4 つです。
S の 1 文字目のみに印をつけたとき T は a
、
S の 2 文字目のみに印をつけたとき T は b
、
S の 3 文字目のみに印をつけたとき T は c
、
S の 1 文字目と 3 文字目のみに印をつけたとき T は ac
、
となります。例えば 1 文字目と 2 文字目の両方に印をつけることはできないことに注意してください。
入力例 2
aa
出力例 2
1
T としてありうるものは a
のみです。
印をつけた位置が異なっていても T が同じ文字列となる可能性があることに注意してください。
入力例 3
acba
出力例 3
6
T としてありうるものは a
、 b
、 c
、 aa
、 ab
、 ca
の 6 つです。
入力例 4
chokudai
出力例 4
54
Score : 500 points
Problem Statement
Given is a string S. From this string, Takahashi will make a new string T as follows.
- First, mark one or more characters in S. Here, no two marked characters should be adjacent.
- Next, delete all unmarked characters.
- Finally, let T be the remaining string. Here, it is forbidden to change the order of the characters.
How many strings are there that can be obtained as T? Find the count modulo (10^9 + 7).
Constraints
- S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained as T, modulo (10^9 + 7).
Sample Input 1
abc
Sample Output 1
4
There are four strings that can be obtained as T: a
, b
, c
, and ac
.
Marking the first character of S yields a
;
marking the second character of S yields b
;
marking the third character of S yields c
;
marking the first and third characters of S yields ac
.
Note that it is forbidden to, for example, mark both the first and second characters.
Sample Input 2
aa
Sample Output 2
1
There is just one string that can be obtained as T, which is a
.
Note that marking different positions may result in the same string.
Sample Input 3
acba
Sample Output 3
6
There are six strings that can be obtained as T: a
, b
, c
, aa
, ab
, and ca
.
Sample Input 4
chokudai
Sample Output 4
54
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
(1, \dots, N) の順列 p = (p_1, \dots, p_N), q = (q_1, \dots, q_N) が与えられます。
(1, \dots, N) の順列 r = (r_1, \dots, r_N) であって、全ての i \, (1 \leq i \leq N) に対し r_i \neq p_i かつ r_i \neq q_i となるようなものの総数を (10^9 + 7) で割った余りを求めてください。
制約
- 1 \leq N \leq 3000
- 1 \leq p_i, q_i \leq N
- p_i \neq p_j \, (i \neq j)
- q_i \neq q_j \, (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N p_1 \ldots p_N q_1 \ldots q_N
出力
答えを出力せよ。
入力例 1
4 1 2 3 4 2 1 4 3
出力例 1
4
(3, 4, 1, 2), (3, 4, 2, 1), (4, 3, 1, 2), (4, 3, 2, 1) の 4 つが条件を満たします。
入力例 2
3 1 2 3 2 1 3
出力例 2
0
答えが 0 になることもあります。
入力例 3
20 2 3 15 19 10 7 5 6 14 13 20 4 18 9 17 8 12 11 16 1 8 12 4 13 19 3 10 16 11 9 1 2 17 6 5 18 7 14 20 15
出力例 3
803776944
(10^9 + 7) で割った余りを出力することに注意してください。
Score : 600 points
Problem Statement
Given are permutations of (1, \dots, N): p = (p_1, \dots, p_N) and q = (q_1, \dots, q_N).
Find the number, modulo (10^9 + 7), of permutations r = (r_1, \dots, r_N) of (1, \dots, N) such that r_i \neq p_i and r_i \neq q_i for every i (1 \leq i \leq N).
Constraints
- 1 \leq N \leq 3000
- 1 \leq p_i, q_i \leq N
- p_i \neq p_j \, (i \neq j)
- q_i \neq q_j \, (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_1 \ldots p_N q_1 \ldots q_N
Output
Print the answer.
Sample Input 1
4 1 2 3 4 2 1 4 3
Sample Output 1
4
There are four valid permutations: (3, 4, 1, 2), (3, 4, 2, 1), (4, 3, 1, 2), and (4, 3, 2, 1).
Sample Input 2
3 1 2 3 2 1 3
Sample Output 2
0
The answer may be 0.
Sample Input 3
20 2 3 15 19 10 7 5 6 14 13 20 4 18 9 17 8 12 11 16 1 8 12 4 13 19 3 10 16 11 9 1 2 17 6 5 18 7 14 20 15
Sample Output 3
803776944
Be sure to print the count modulo (10^9 + 7).
Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
N 頂点 M 辺の有向グラフがあります。
頂点は 1, \dots, N と番号付けられており、i \, (1 \leq i \leq M) 番目の辺は頂点 A_i から頂点 B_i に向けて張られています。
はじめ、頂点 i \, ( 1 \leq i \leq N) には X_i 個の落とし物があります。これらの落とし物を K 人で拾うことになりました。
K 人は 1 人ずつグラフ上を移動します。各々は次のような行動をとります。
- 頂点 1 から出発し、辺をたどって移動することを任意の有限回繰り返す。訪れた各頂点(頂点 1 も含む)について、落とし物がまだ拾われていなければ、全て拾う。
合計で最大何個の落とし物を拾うことができるか求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq 10
- 1 \leq A_i, B_i \leq N
- A_i \neq B_i
- i \neq j ならば、A_i \neq A_j または B_i \neq B_j
- 1 \leq X_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 B_1 \vdots A_M B_M X_1 \ldots X_N
出力
答えを出力せよ。
入力例 1
5 5 2 1 2 2 3 3 2 1 4 1 5 1 4 5 2 8
出力例 1
18
2 人がそれぞれ次のように行動することで、18 個の落とし物を拾うことができます。
- 1 人目は、頂点 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 の順に移動し、頂点 1, 2, 3 にある落とし物を拾う。
- 2 人目は、頂点 1 \rightarrow 5 の順に移動し、頂点 5 にある落とし物を拾う。
19 個以上の落とし物を拾うことはできないので、18 を出力します。
入力例 2
3 1 10 2 3 1 100 100
出力例 2
1
Score : 600 points
Problem Statement
There is a directed graph with N vertices and M edges.
The vertices are numbered 1, \dots, N, and the i-th edge (1 \leq i \leq M) goes from Vertex A_i to Vertex B_i.
Initially, there are X_i items on Vertex i (1 \leq i \leq N) that someone has lost. K people will collect these items.
The K people will travel in the graph one by one. Each person will do the following.
- Start on Vertex 1. Then, traverse an edge any finite number of times. For each vertex visited (including Vertex 1), collect all items on it if they have not been collected yet.
Find the maximum total number of items that can be collected.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq 10
- 1 \leq A_i, B_i \leq N
- A_i \neq B_i
- A_i \neq A_j or B_i \neq B_j, if i \neq j.
- 1 \leq X_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K A_1 B_1 \vdots A_M B_M X_1 \ldots X_N
Output
Print the answer.
Sample Input 1
5 5 2 1 2 2 3 3 2 1 4 1 5 1 4 5 2 8
Sample Output 1
18
The two people can collect 18 items as follows.
- The first person goes 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 and collects the items on Vertices 1, 2, and 3.
- The second person goes 1 \rightarrow 5 and collects the items on Vertex 5.
It is impossible to collect 19 or more items, so we should print 18.
Sample Input 2
3 1 10 2 3 1 100 100
Sample Output 2
1