実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は鎧を着ています。
この鎧は威力(整数で表される攻撃の強さ)が D 以下の攻撃をすべて防ぎますが、威力が D より大きい攻撃は防ぎません。
この鎧は威力が A の攻撃を防ぎますか。
制約
- 1 \leq A \leq 100
- 1 \leq D \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A D
出力
鎧が攻撃を防ぐなら Yes、防がないなら No と出力せよ。
入力例 1
4 5
出力例 1
Yes
この例では A = 4, D = 5 です。A = 4 は D = 5 以下であるため鎧は攻撃を防ぎ、答えは Yes です。
入力例 2
5 5
出力例 2
Yes
この例では A = 5, D = 5 です。A = 5 は D = 5 以下であるため鎧は攻撃を防ぎ、答えは Yes です。
入力例 3
6 5
出力例 3
No
この例では A = 6, D = 5 です。A = 6 は D = 5 以下でないため鎧は攻撃を防がず、答えは No です。
Score : 100 points
Problem Statement
Takahashi is wearing armor.
This armor blocks all attacks with power (strength represented as an integer) of D or less, but does not block attacks with power greater than D.
Does this armor block an attack with power A?
Constraints
- 1 \leq A \leq 100
- 1 \leq D \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A D
Output
Output Yes if the armor blocks the attack, and No otherwise.
Sample Input 1
4 5
Sample Output 1
Yes
In this sample, A = 4 and D = 5. Since A = 4 is at most D = 5, the armor blocks the attack, so the answer is Yes.
Sample Input 2
5 5
Sample Output 2
Yes
In this sample, A = 5 and D = 5. Since A = 5 is at most D = 5, the armor blocks the attack, so the answer is Yes.
Sample Input 3
6 5
Sample Output 3
No
In this sample, A = 6 and D = 5. Since A = 6 is not at most D = 5, the armor does not block the attack, so the answer is No.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の木こり 1,2,\dots,N が斧を 1 個ずつ持っています。
全員が斧を池に落としてしまいました。
池に N 個の斧 1,2,\dots,N が沈んでいました。
各木こり i は「自分が持っていた斧は斧 A_i である」と主張しています。
一方、この池の女神は、各斧 i を持っていたのは木こり B_i であることを知っています。
N 人の木こり全員が本当のことを言っているかどうかを判定してください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i \leq N
- 1 \leq B_i \leq N
- A_i \neq A_j\;(i \neq j)
- B_i \neq B_j\;(i \neq j)
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
N 人の木こり全員が本当のことを言っているならば Yes を、そうでないならば No を出力せよ。
入力例 1
3 3 1 2 2 3 1
出力例 1
Yes
N 人の木こり全員が本当のことを言っています。
入力例 2
4 1 2 3 4 1 3 2 4
出力例 2
No
木こり 2,3 の 2 人は嘘をついています。
入力例 3
5 2 4 5 1 3 4 1 5 2 3
出力例 3
Yes
Score : 200 points
Problem Statement
N woodcutters 1, 2, \dots, N each have one axe.
All of them dropped their axes into a pond.
N axes 1, 2, \dots, N were found sunk in the pond.
Each woodcutter i claims that "I owned axe A_i."
On the other hand, the goddess of this pond knows that the woodcutter who owned axe i is woodcutter B_i.
Determine whether all N woodcutters are telling the truth.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i \leq N
- 1 \leq B_i \leq N
- A_i \neq A_j\;(i \neq j)
- B_i \neq B_j\;(i \neq j)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Output Yes if all N woodcutters are telling the truth, and No otherwise.
Sample Input 1
3 3 1 2 2 3 1
Sample Output 1
Yes
All N woodcutters are telling the truth.
Sample Input 2
4 1 2 3 4 1 3 2 4
Sample Output 2
No
Woodcutters 2 and 3 are lying.
Sample Input 3
5 2 4 5 1 3 4 1 5 2 3
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N 個の宝石があります。i 番目の宝石の色(整数で表されます)は C_i で価値は V_i です。
この N 個の宝石の中から K 個を選びます。ただし、選んだ宝石の色が M 種類以上なければなりません。
このとき、選んだ宝石の価値の総和としてありうる最大値を求めてください。(与えられる入力では、このような選択が必ず可能です。)
制約
- 1 \leq M \leq K \leq N \leq 2 \times 10^5
- 1 \leq C_i \leq N
- 1 \leq V_i \leq 10^9
- M 種類以上の色の宝石が存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K M C_1 V_1 C_2 V_2 \vdots C_N V_N
出力
選んだ宝石の価値の総和としてありうる最大値を整数として出力せよ。
入力例 1
5 3 2 1 30 1 40 1 50 2 10 3 20
出力例 1
110
この例では 5 個の宝石から 3 個を選びます。選んだ宝石の色が 2 種類以上なければなりません。
宝石 2, 3, 5 を選ぶと、それらの色は 1, 1, 3 で 2 種類あります。それらの価値の総和は 40 + 50 + 20 = 110 で、これがありうる最大値です。
入力例 2
5 3 3 1 30 1 40 1 50 2 10 3 20
出力例 2
80
宝石や選ぶ個数は入力例 1 と同じですが、選んだ宝石の色が 3 種類以上なければなりません。
宝石 3, 4, 5 を選ぶと、それらの色は 1, 2, 3 で 3 種類あります。それらの価値の総和は 50 + 10 + 20 = 80 で、これがありうる最大値です。
入力例 3
5 5 1 4 1000000000 5 1000000000 4 1000000000 5 1000000000 4 1000000000
出力例 3
5000000000
オーバーフローに注意してください。
Score : 300 points
Problem Statement
There are N gems. The color (represented as an integer) of the i-th gem is C_i and its value is V_i.
Choose K gems from these N gems. Here, the chosen gems must have at least M distinct colors.
Find the maximum possible total value of the chosen gems. (Such a choice is always possible in the given input.)
Constraints
- 1 \leq M \leq K \leq N \leq 2 \times 10^5
- 1 \leq C_i \leq N
- 1 \leq V_i \leq 10^9
- There exist gems of at least M distinct colors.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K M C_1 V_1 C_2 V_2 \vdots C_N V_N
Output
Output the maximum possible total value of the chosen gems as an integer.
Sample Input 1
5 3 2 1 30 1 40 1 50 2 10 3 20
Sample Output 1
110
In this sample, choose three gems from five gems. The chosen gems must have at least two distinct colors.
Choosing gems 2, 3, 5 gives colors 1, 1, 3, which are two distinct colors. Their total value is 40 + 50 + 20 = 110, and this is the maximum possible value.
Sample Input 2
5 3 3 1 30 1 40 1 50 2 10 3 20
Sample Output 2
80
The gems and the number to choose are the same as in Sample Input 1, but the chosen gems must have at least three distinct colors.
Choosing gems 3, 4, 5 gives colors 1, 2, 3, which are three distinct colors. Their total value is 50 + 10 + 20 = 80, and this is the maximum possible value.
Sample Input 3
5 5 1 4 1000000000 5 1000000000 4 1000000000 5 1000000000 4 1000000000
Sample Output 3
5000000000
Beware of overflow.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 425 点
問題文
H \times W のグリッドがあり、各マスには 0 または 1 の整数が書き込まれています。
各マスに書き込まれた整数の情報は H 個の長さ W の文字列 S_1,S_2,\dots,S_H として与えられます。
S_i の j 文字目が 0 である時はグリッドの上から i 行目、左から j 列目に 0 が書き込まれており、 S_i の j 文字目が 1 である時はグリッドの上から i 行目、左から j 列目に 1 が書き込まれています。
書き込まれた整数の総和が K となる長方形領域がいくつあるか求めてください。
厳密には、以下の条件を全て満たす整数の四つ組 (r_1,c_1,r_2,c_2) がいくつあるか求めてください。
- 1 \le r_1 \le r_2 \le H
- 1 \le c_1 \le c_2 \le W
- グリッドの上から i 行目、左から j 列目に書き込まれた整数を、 r_1 \le i \le r_2, c_1 \le j \le c_2 を満たす全ての整数組 (i,j) について足し合わせた値が K である。
制約
- H,W は 1 以上 500 以下の整数
- K は 0 以上 HW 以下の整数
- S_i は
0,1からなる長さ W の文字列
入力
入力は以下の形式で標準入力から与えられる。
H W K S_1 S_2 \vdots S_H
出力
答えを出力せよ。
入力例 1
3 4 3 1001 1101 0110
出力例 1
8
書き込まれた整数の総和が K となる長方形領域は以下の 8 個です。
- 上から 1 行目から 2 行目、左から 1 列目から 2 列目を抜き出した長方形領域
- 上から 1 行目から 2 行目、左から 1 列目から 3 列目を抜き出した長方形領域
- 上から 1 行目から 2 行目、左から 2 列目から 4 列目を抜き出した長方形領域
- 上から 1 行目から 3 行目、左から 2 列目から 3 列目を抜き出した長方形領域
- 上から 1 行目から 3 行目、左から 3 列目から 4 列目を抜き出した長方形領域
- 上から 2 行目から 2 行目、左から 1 列目から 4 列目を抜き出した長方形領域
- 上から 2 行目から 3 行目、左から 1 列目から 2 列目を抜き出した長方形領域
- 上から 2 行目から 3 行目、左から 2 列目から 3 列目を抜き出した長方形領域
入力例 2
5 4 20 0101 1010 0101 1010 0101
出力例 2
0
入力例 3
15 20 17 10111101101100000100 01100000000010000011 01110010111000111000 11001100000111011000 10100001100011100010 01101000101010000101 10110001111110000100 10110011101100101101 01010001110011001001 01010110010001100110 01110100011110011110 01100000100111010010 11001101100111101100 10111100010101111011 00101101011100010000
出力例 3
448
Score : 425 points
Problem Statement
There is an H \times W grid, and each cell contains an integer 0 or 1.
The information of the integer written in each cell is given as H strings S_1, S_2, \dots, S_H of length W.
If the j-th character of S_i is 0, then 0 is written in the cell at the i-th row from the top and the j-th column from the left of the grid; if the j-th character of S_i is 1, then 1 is written in that cell.
Find the number of rectangular regions where the sum of the written integers equals K.
More formally, find the number of quadruples of integers (r_1, c_1, r_2, c_2) satisfying all of the following conditions:
- 1 \le r_1 \le r_2 \le H
- 1 \le c_1 \le c_2 \le W
- The sum of the integers written in the cell at the i-th row from the top and the j-th column from the left, over all pairs of integers (i, j) satisfying r_1 \le i \le r_2, c_1 \le j \le c_2, equals K.
Constraints
- H and W are integers between 1 and 500, inclusive.
- K is an integer between 0 and HW, inclusive.
- S_i is a string of length W consisting of
0and1.
Input
The input is given from Standard Input in the following format:
H W K S_1 S_2 \vdots S_H
Output
Output the answer.
Sample Input 1
3 4 3 1001 1101 0110
Sample Output 1
8
There are eight rectangular regions where the sum of the written integers equals K:
- The rectangular region extracted from row 1 to row 2 from the top and column 1 to column 2 from the left
- The rectangular region extracted from row 1 to row 2 from the top and column 1 to column 3 from the left
- The rectangular region extracted from row 1 to row 2 from the top and column 2 to column 4 from the left
- The rectangular region extracted from row 1 to row 3 from the top and column 2 to column 3 from the left
- The rectangular region extracted from row 1 to row 3 from the top and column 3 to column 4 from the left
- The rectangular region extracted from row 2 to row 2 from the top and column 1 to column 4 from the left
- The rectangular region extracted from row 2 to row 3 from the top and column 1 to column 2 from the left
- The rectangular region extracted from row 2 to row 3 from the top and column 2 to column 3 from the left
Sample Input 2
5 4 20 0101 1010 0101 1010 0101
Sample Output 2
0
Sample Input 3
15 20 17 10111101101100000100 01100000000010000011 01110010111000111000 11001100000111011000 10100001100011100010 01101000101010000101 10110001111110000100 10110011101100101101 01010001110011001001 01010110010001100110 01110100011110011110 01100000100111010010 11001101100111101100 10111100010101111011 00101101011100010000
Sample Output 3
448
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
N 行 N 列のグリッドがあります。はじめ、すべてのマスは白く塗られています。
Q 回のクエリを与えられる順に処理してください。各クエリは以下のいずれかです。
- タイプ 1: 整数 R が与えられる。グリッドの上から R 行目のマスをすべて黒く塗る。
- タイプ 2: 整数 C が与えられる。グリッドの左から C 列目のマスをすべて白く塗る。
クエリを処理するたびに、処理が完了した時点でのグリッド内で黒く塗られているマスの個数を出力してください。
制約
- 1 \leq N, Q \leq 3 \times 10^5
- タイプ 1 のクエリについて 1 \leq R \leq N
- タイプ 2 のクエリについて 1 \leq C \leq N
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
ここで、\text{query}_i が i 回目のクエリであり、以下のいずれかの形式で与えられる。
タイプ 1:
1 R
タイプ 2:
2 C
出力
Q 行出力せよ。i 行目には、i 回目のクエリの処理が完了した時点でのグリッド内で黒く塗られているマスの個数を出力せよ。
入力例 1
3 4 1 1 1 3 2 2 1 1
出力例 1
3 6 4 5
グリッドの変化を文字で表します。. が白いマス、# が黒いマスを表します。
... ### ### #.# ### ... -> ... -> ... -> ... -> ... ... ... ### #.# #.#
入力例 2
300000 1 2 300000
出力例 2
0
より大きなケースでのオーバーフローに注意してください。
Score : 475 points
Problem Statement
There is an N \times N grid. Initially, all cells are painted white.
Process Q queries in the given order. Each query is one of the following:
- Type 1: An integer R is given. Paint all cells in the R-th row from the top of the grid black.
- Type 2: An integer C is given. Paint all cells in the C-th column from the left of the grid white.
After processing each query, output the number of black cells in the grid at that point.
Constraints
- 1 \leq N, Q \leq 3 \times 10^5
- For type 1 queries, 1 \leq R \leq N.
- For type 2 queries, 1 \leq C \leq N.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Here, \text{query}_i is the i-th query, given in one of the following formats.
Type 1:
1 R
Type 2:
2 C
Output
Output Q lines. The i-th line should contain the number of black cells in the grid at the time the i-th query has been processed.
Sample Input 1
3 4 1 1 1 3 2 2 1 1
Sample Output 1
3 6 4 5
The changes in the grid are shown using characters. . represents a white cell, and # represents a black cell.
... ### ### #.# ### ... -> ... -> ... -> ... -> ... ... ... ### #.# #.#
Sample Input 2
300000 1 2 300000
Sample Output 2
0
Beware of overflow in larger cases.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
正整数 N が与えられます。
以下の条件をすべて満たす空でない正整数列 A を良い数列と呼ぶことにします。
- A の各要素は相異なる
- A の要素の総積は N に等しい
数列のスコアを、その数列の要素の総和で定義します。
すべての良い数列のスコアの合計を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 10^{10}
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを 1 行で出力せよ。
入力例 1
8
出力例 1
80
良い数列は (1,2,4),(1,4,2),(1,8),(2,1,4),(2,4),(2,4,1),(4,1,2),(4,2),(4,2,1),(8),(8,1) の 11 個です。
これらのスコアの合計は 7+7+9+7+6+7+7+6+7+8+9=80 です。
入力例 2
461
出力例 2
1385
入力例 3
100
出力例 3
1702
Score : 500 points
Problem Statement
You are given a positive integer N.
We call a non-empty sequence of positive integers A a good sequence if it satisfies all of the following conditions:
- All elements of A are distinct.
- The product of all elements of A equals N.
The score of a sequence is defined as the sum of all elements of the sequence.
Find the sum, modulo 998244353, of the scores of all good sequences.
Constraints
- 1 \leq N \leq 10^{10}
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Output the answer on a single line.
Sample Input 1
8
Sample Output 1
80
There are 11 good sequences: (1,2,4),(1,4,2),(1,8),(2,1,4),(2,4),(2,4,1),(4,1,2),(4,2),(4,2,1),(8),(8,1).
The sum of their scores is 7+7+9+7+6+7+7+6+7+8+9=80.
Sample Input 2
461
Sample Output 2
1385
Sample Input 3
100
Sample Output 3
1702
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 625 点
問題文
N 頂点 M 辺の単純無向グラフがあります。
各頂点には 1 から N の番号が、各辺には 1 から M の番号が付いており、辺 i は頂点 u_i と v_i を結んでいます。
以下の条件を満たすように、各頂点 j に 2026 以下の非負整数の重み W_j を割り当てます。
- 各辺 i について、W_{u_i}+W_{v_i} \leq 2026
すべての頂点の重みの合計(すなわち \sum_{j=1}^{N}{W_j})としてあり得る値の最大値を求めてください。
制約
- 1 \leq N \leq 5 \times 10^4
- 0 \leq M \leq 5 \times 10^4
- 1 \leq u_i \lt v_i \leq N
- (u_1,v_1),(u_2,v_2),\dots,(u_M,v_M) は相異なる
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
答えを 1 行で出力せよ。
入力例 1
3 2 1 2 2 3
出力例 1
4052
頂点 1,2,3 にそれぞれ 2026,0,2026 の重みを割り当てることで、すべての頂点の重みの合計は 4052 となり、またこれより大きくすることはできないため、答えは 4052 となります。
入力例 2
4 6 1 2 2 3 1 4 2 4 1 3 3 4
出力例 2
4052
入力例 3
2 1 1 2
出力例 3
2026
Score : 625 points
Problem Statement
There is a simple undirected graph with N vertices and M edges.
The vertices are numbered 1 through N and the edges are numbered 1 through M; edge i connects vertices u_i and v_i.
Assign a non-negative integer weight W_j not greater than 2026 to each vertex j so that the following condition is satisfied:
- W_{u_i}+W_{v_i} \leq 2026 for each edge i.
Find the maximum possible value of the sum of all vertex weights (that is, \sum_{j=1}^{N}{W_j}).
Constraints
- 1 \leq N \leq 5 \times 10^4
- 0 \leq M \leq 5 \times 10^4
- 1 \leq u_i \lt v_i \leq N
- (u_1,v_1),(u_2,v_2),\dots,(u_M,v_M) are pairwise distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Output the answer on a single line.
Sample Input 1
3 2 1 2 2 3
Sample Output 1
4052
By assigning weights 2026, 0, 2026 to vertices 1, 2, 3, respectively, the sum of all vertex weights becomes 4052, and it is impossible to make it larger, so the answer is 4052.
Sample Input 2
4 6 1 2 2 3 1 4 2 4 1 3 3 4
Sample Output 2
4052
Sample Input 3
2 1 1 2
Sample Output 3
2026