Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。
つまり、 ID は以下の順番で付けられています。
- 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
- ...
このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。
制約
- S は AtCoder Big Contest に含まれる問題の ID として正しい
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
AB
出力例 1
28
ID が AB である問題は、 AtCoder Big Contest の 28 問目です。
入力例 2
C
出力例 2
3
ID が C である問題は、 AtCoder Big Contest の 3 問目です。
入力例 3
BRUTMHYHIIZP
出力例 3
10000000000000000
ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。
Score : 300 points
Problem Statement
In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...
In other words, the IDs are given in the following order:
- the strings of length 1 consisting of uppercase English letters, in lexicographical order;
- the strings of length 2 consisting of uppercase English letters, in lexicographical order;
- the strings of length 3 consisting of uppercase English letters, in lexicographical order;
- ...
Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)
Constraints
- S is a valid ID of a problem given in AtCoder Big Contest.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
AB
Sample Output 1
28
The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.
Sample Input 2
C
Sample Output 2
3
The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.
Sample Input 3
BRUTMHYHIIZP
Sample Output 3
10000000000000000
The problem whose ID is BRUTMHYHIIZP is the
10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
xy -平面上にいくつかのイチゴが載った長方形のケーキがあります。 ケーキは、長方形領域 \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace をちょうど占めます。
ケーキには N 個のイチゴが載っており、i = 1, 2, \ldots, N について、i 番目のイチゴの座標は (p_i, q_i) です。 2 個以上のイチゴが同一の座標にあることはありません。
高橋君は、このケーキを包丁で下記の通りにいくつかのピースに切り分けます。
- まず、ケーキを通る y 軸に並行な A 本の異なる直線、直線 x = a_1 、直線 x = a_2 、\ldots 、直線 x = a_A のそれぞれにそってケーキを切る。
- 次に、ケーキを通る x 軸に並行な B 本の異なる直線、直線 y = b_1 、直線 y = b_2 、\ldots 、直線 y = b_B のそれぞれにそってケーキを切る。
その結果、ケーキは (A+1)(B+1) 個の長方形のピースに分割されます。 高橋君はそれらのうちのいずれか 1 個だけを選んで食べます。 高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値と最大値をそれぞれ出力してください。
ここで、最終的にピースの縁となる位置にはイチゴが存在しないことが保証されます。 より形式的な説明は下記の制約を参照してください。
制約
- 3 \leq W, H \leq 10^9
- 1 \leq N \leq 2 \times 10^5
- 0 \lt p_i \lt W
- 0 \lt q_i \lt H
- i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
- 1 \leq A, B \leq 2 \times 10^5
- 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
- 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
- p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
- q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
W H N p_1 q_1 p_2 q_2 \vdots p_N q_N A a_1 a_2 \ldots a_A B b_1 b_2 \ldots b_B
出力
高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値 m と最大値 M をそれぞれ、下記の形式の通り空白区切りで出力せよ。
m M
入力例 1
7 6 5 6 1 3 1 4 2 1 5 6 2 2 2 5 2 3 4
出力例 1
0 2
全 9 個のピースの内訳は、イチゴが 0 個載ったものが 6 個、イチゴが 1 個載ったものが 1 個、イチゴが 2 個載ったものが 2 個です。 よって、それらのうちのいずれか 1 個だけを選んで食べるとき、選んだピースに載っているイチゴの個数としてあり得る最小値は 0 、最大値は 2 です。
入力例 2
4 4 4 1 1 3 1 3 3 1 3 1 2 1 2
出力例 2
1 1
どのピースにもイチゴが 1 個載っています。
Score : 400 points
Problem Statement
There is a rectangular cake with some strawberries on the xy-plane. The cake occupies the rectangular area \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace.
There are N strawberries on the cake, and the coordinates of the i-th strawberry are (p_i, q_i) for i = 1, 2, \ldots, N. No two strawberries have the same coordinates.
Takahashi will cut the cake into several pieces with a knife, as follows.
- First, cut the cake along A different lines parallel to the y-axis: lines x = a_1, x = a_2, \ldots, x = a_A.
- Next, cut the cake along B different lines parallel to the x-axis: lines y = b_1, y = b_2, \ldots, y = b_B.
As a result, the cake will be divided into (A+1)(B+1) rectangular pieces. Takahashi will choose just one of these pieces to eat. Print the minimum and maximum possible numbers of strawberries on the chosen piece.
Here, it is guaranteed that there are no strawberries along the edges of the final pieces. For a more formal description, refer to the constraints below.
Constraints
- 3 \leq W, H \leq 10^9
- 1 \leq N \leq 2 \times 10^5
- 0 \lt p_i \lt W
- 0 \lt q_i \lt H
- i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
- 1 \leq A, B \leq 2 \times 10^5
- 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
- 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
- p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
- q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
- All input values are integers.
Input
The input is given from Standard Input in the following format:
W H N p_1 q_1 p_2 q_2 \vdots p_N q_N A a_1 a_2 \ldots a_A B b_1 b_2 \ldots b_B
Output
Print the minimum possible number of strawberries m and the maximum possible number M on the chosen piece in the following format, separated by a space.
m M
Sample Input 1
7 6 5 6 1 3 1 4 2 1 5 6 2 2 2 5 2 3 4
Sample Output 1
0 2
There are nine pieces in total: six with zero strawberries, one with one strawberry, and two with two strawberries. Therefore, when choosing just one of these pieces to eat, the minimum possible number of strawberries on the chosen piece is 0, and the maximum possible number is 2.
Sample Input 2
4 4 4 1 1 3 1 3 3 1 3 1 2 1 2
Sample Output 2
1 1
Each piece has one strawberry on it.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
1 から N までの番号がついた N 冊の本があります。
本 i には C_i 冊の前提となる本があり、そのうち j 冊目は本 P_{i,j} で、本 i を読む前にこの C_i 冊をすべて読む必要があります。
ただし、適切な順序を選ぶことですべての本を読むことができます。
あなたは本 1 を読むために必要な最小の数の本を読もうとしています。
本 1 以外に読まなければならない本の番号を読むべき順に出力してください。ただし、この条件下で読むべき本の集合は一意に定まります。
条件を満たす読む順番が複数考えられる場合は、そのいずれを出力しても構いません。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq C_i < N
- \sum_{i=1}^{N} C_i \leq 2 \times 10^5
- C_1 \geq 1
- 1 \leq P_{i,j} \leq N
- 1 \leq j < k \leq C_i のとき P_{i,j} \neq P_{i,k}
- すべての本を読むことが可能である
入力
入力は以下の形式で標準入力から与えられる。
N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}
出力
本 1 を読むために読む必要のある最小の数の本を読むとき、それらの番号を読むべき順に空白区切りで出力せよ。
入力例 1
6 3 2 3 4 2 3 5 0 1 5 0 0
出力例 1
5 3 4 2
本 1 を読むために本 2,3,4、本 2 を読むために本 3,5、本 4 を読むために本 5 を読む必要があります。本 3,5,6 を読むために他の本を読む必要はありません。
このとき、例えば本 5,3,4,2 の順に読むことで本 1 を読むことができます。3 冊以下の本を読んだ状態で本 1 が読めるようになることはないため、これは答えの一つです。他にも本 3,5,4,2 の順などで読むことでも 4 冊の本を読んだ状態で本 1 を読むことができるようになります。
入力例 2
6 1 2 1 3 1 4 1 5 1 6 0
出力例 2
6 5 4 3 2
入力例 3
8 1 5 1 6 1 7 1 8 0 0 0 0
出力例 3
5
Score : 425 points
Problem Statement
We have N books numbered 1 to N.
Book i assumes that you have read C_i books, the j-th of which is book P_{i,j}: you must read all these C_i books before reading book i.
Here, you can read all the books in some order.
You are trying to read the minimum number of books required to read book 1.
Print the numbers of the books you must read excluding book 1 in the order they should be read. Under this condition, the set of books to read is uniquely determined.
If there are multiple reading orders that satisfy the condition, you may print any of them.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq C_i < N
- \sum_{i=1}^{N} C_i \leq 2 \times 10^5
- C_1 \geq 1
- 1 \leq P_{i,j} \leq N
- P_{i,j} \neq P_{i,k} for 1 \leq j < k \leq C_i.
- It is possible to read all the books.
Input
The input is given from Standard Input in the following format:
N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}
Output
Print the numbers of the books you must read to read book 1 in the order they should be read, with spaces in between.
Sample Input 1
6 3 2 3 4 2 3 5 0 1 5 0 0
Sample Output 1
5 3 4 2
To read book 1, you must read books 2,3,4; to read book 2, you must read books 3,5; to read book 4, you must read book 5. To read books 3,5,6, you do not have to read any other books.
For example, if you read books 5,3,4,2 in this order, you can read book 1. This is a correct answer, because you will never be able to read book 1 with three or fewer books read. As another example, reading books 3,5,4,2 in this order also allows you to read book 1 with 4 books read.
Sample Input 2
6 1 2 1 3 1 4 1 5 1 6 0
Sample Output 2
6 5 4 3 2
Sample Input 3
8 1 5 1 6 1 7 1 8 0 0 0 0
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
箱を用意します。最初、箱は空です。
この箱に対して、以下の 2 種類の操作を合計 Q 個、入力で与えられた順に施します。
+ x
タイプ 1 : 箱の中に整数 x の書かれたボールを 1 つ追加する。
- x
タイプ 2 : 箱の中にある、整数 x の書かれたボールを 1 つ取り除く。
但し、取り除く前の時点で箱の中に整数 x が書かれたボールが含まれることが保証されます。
各操作後の箱に関して、以下の問題を解いてください。
箱からボールをいくつか取り出して、ボールに書かれた整数の総和を K とする方法の総数を 998244353 で割った余りを求めてください。
但し、箱の中に入っている全てのボールは区別可能です。
制約
- 入力は全て整数
- 1 \le Q \le 5000
- 1 \le K \le 5000
- タイプ 1 の操作に関して、 1 \le x \le 5000
- 全ての操作は問題文中の条件を満たす。
入力
入力は以下の形式で標準入力から与えられる。
但し、 \rm{Query}_{i} は i 個目の操作を表す。
Q K
\rm{Query}_{1}
\rm{Query}_{2}
\vdots
\rm{Query}_{Q}
出力
全体で Q 行出力せよ。
そのうち i 行目には、 i 個目までの操作を終えた時点での答えを出力せよ。
入力例 1
15 10 + 5 + 2 + 3 - 2 + 5 + 10 - 3 + 1 + 3 + 3 - 5 + 1 + 7 + 4 - 3
出力例 1
0 0 1 0 1 2 2 2 2 2 1 3 5 8 5
この入力には、操作が 15 個含まれます。
最後の操作の後、箱の中に入ったボールは (5,10,1,3,1,7,4) となります。
総和を 10 にする方法は以下の 5 通りです。
- 5+1+3+1 ( 1,3,4,5 番目のボールを取り出す )
- 5+1+4 ( 1,3,7 番目のボールを取り出す )
- 5+1+4 ( 1,5,7 番目のボールを取り出す )
- 10 ( 2 番目のボールを取り出す )
- 3+7 ( 4,6 番目のボールを取り出す )
Score : 525 points
Problem Statement
We have a box, which is initially empty.
Let us perform a total of Q operations of the following two types in the order they are given in the input.
+ x
Type 1: Put into the box a ball with the integer x written on it.
- x
Type 2: Remove from the box a ball with the integer x written on it.
It is guaranteed that the box contains a ball with the integer x written on it before the operation.
For the box after each operation, solve the following problem.
Find the number, modulo 998244353, to pick up some number of balls from the box so that the integers written on them sum to K.
All balls in the box are distinguishable.
Constraints
- All input values are integers.
- 1 \le Q \le 5000
- 1 \le K \le 5000
- For each type-1 operation, 1 \le x \le 5000.
- All the operations satisfy the condition in the problem statement.
Input
The input is given from Standard Input in the following format, where \mathrm{Query}_i represents the i-th operation:
Q K
\rm{Query}_{1}
\rm{Query}_{2}
\vdots
\rm{Query}_{Q}
Output
Print Q lines.
The i-th line should contain the answer when the first i operations have been done.
Sample Input 1
15 10 + 5 + 2 + 3 - 2 + 5 + 10 - 3 + 1 + 3 + 3 - 5 + 1 + 7 + 4 - 3
Sample Output 1
0 0 1 0 1 2 2 2 2 2 1 3 5 8 5
This input contains 15 operations.
After the last operation, the box contains the balls (5,10,1,3,1,7,4).
There are five ways to pick up balls for a sum of 10:
- 5+1+3+1 (the 1-st, 3-rd, 4-th, 5-th balls)
- 5+1+4 (the 1-st, 3-rd, 7-th balls)
- 5+1+4 (the 1-st, 5-th, 7-th balls)
- 10 (the 2-nd ball)
- 3+7 (the 4-th, 6-th balls)