Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder では、ユーザーのレートは正の整数で与えられ、その値に応じて ^ がいくつか表示されます。
特に、レートが 1 以上 399 以下のときは次のようになります。
- レートが 1 以上 99 以下のときは
^は 1 個表示される。 - レートが 100 以上 199 以下のときは
^は 2 個表示される。 - レートが 200 以上 299 以下のときは
^は 3 個表示される。 - レートが 300 以上 399 以下のときは
^は 4 個表示される。
現在の高橋君のレートは R です。ここで、R は 1 以上 299 以下の整数であることが保証されます。
表示される ^ の数を現在より増やすために、高橋君は少なくともレートをいくつ上げる必要があるか答えてください。
なお、本問題の制約下で、高橋君はレートを 400 以上に上げることなく ^ の数を増やすことができることが証明できます。
制約
- 1\leq R \leq 299
- R は整数
入力
入力は以下の形式で標準入力から与えられる。
R
出力
表示される ^ の数を現在より増やすために、高橋君は少なくともレートをいくつ上げる必要があるか整数で出力せよ。
入力例 1
123
出力例 1
77
高橋君の現在のレートは 123 であり、^ は 2 個表示されています。
ここからレートを 77 上げると高橋君のレートは 200 となり、^ は 3 個表示されるようになります。
レート が 199 以下のときは ^ の数は 2 個以下であるので、77 を出力します。
入力例 2
250
出力例 2
50
Score : 100 points
Problem Statement
In AtCoder, a user's rating is given as a positive integer, and based on this value, a certain number of ^ is displayed.
Specifically, when the rating is between 1 and 399, inclusive, the display rules are as follows:
- When the rating is between 1 and 99, inclusive,
^is displayed once. - When the rating is between 100 and 199, inclusive,
^is displayed twice. - When the rating is between 200 and 299, inclusive,
^is displayed three times. - When the rating is between 300 and 399, inclusive,
^is displayed four times.
Currently, Takahashi's rating is R. Here, it is guaranteed that R is an integer between 1 and 299, inclusive.
Find the minimum increase in rating required for him to increase the number of displayed ^.
It can be proved that under the constraints of this problem, he can increase the number of ^ without raising his rating to 400 or above.
Constraints
- 1 \leq R \leq 299
- R is an integer.
Input
The input is given from Standard Input in the following format:
R
Output
Print, as an integer, the minimum increase in rating required for Takahashi to increase the number of displayed ^.
Sample Input 1
123
Sample Output 1
77
Takahashi's current rating is 123, and ^ is displayed twice.
By increasing his rating by 77, his rating will become 200, and ^ will be displayed three times.
When the rating is 199 or below, ^ is displayed not more than twice, so print 77.
Sample Input 2
250
Sample Output 2
50
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英大文字および英小文字からなる文字列 S が与えられます。
ここで、 S のうちちょうど 1 文字だけが英大文字であり、それ以外は全て英小文字です。
大文字が S の先頭から何文字目に登場するか出力してください。
ただし、S の先頭の文字を 1 文字目とします。
制約
- S は英大文字および英小文字からなる長さ 2 以上 100 以下の文字列
- S に大文字はちょうど 1 つ含まれる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
大文字が S の先頭から何文字目に登場するかを、整数で出力せよ。
入力例 1
aBc
出力例 1
2
aBc の先頭から 1 文字目は a , 2 文字目は B , 3 文字目は c であり、
このうち大文字は 2 文字目です。
よって、2 を出力します。
入力例 2
xxxxxxXxxx
出力例 2
7
S=xxxxxxXxxx の 7 文字目に、大文字である X が登場しています。よって、7 を出力します。
入力例 3
Zz
出力例 3
1
Score : 100 points
Problem Statement
You are given a string S consisting of uppercase and lowercase English letters.
Here, exactly one character of S is uppercase, and the others are all lowercase.
Find the integer x such that the x-th character of S is uppercase.
Here, the initial character of S is considered the 1-st one.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of uppercase and lowercase English letters.
- S has exactly one uppercase letter.
Input
The input is given from Standard Input in the following format:
S
Output
Print the integer x such that the x-th character of S is uppercase.
Sample Input 1
aBc
Sample Output 1
2
The 1-st character of aBc is a, the 2-nd is B, and the 3-rd is c;
the 2-nd character is uppercase.
Thus, 2 should be printed.
Sample Input 2
xxxxxxXxxx
Sample Output 2
7
An uppercase letter X occurs as the 7-th character of S=xxxxxxXxxx, so 7 should be printed.
Sample Input 3
Zz
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 N が与えられます。
N 行 N 列のマス目があり、上から i 行目、左から j 列目のマスには数字 A_{i,j} が書かれています。
このマス目は上下および左右がつながっているものとします。つまり以下が全て成り立ちます。
- (1,i) の上のマスは (N,i) であり、(N,i) の下のマスは (1,i) である。(1\le i\le N)
- (i,1) の左のマスは (i,N) であり、(i,N) の右のマスは (i,1) である。(1\le i\le N)
高橋君は、上下左右および斜めの 8 方向のうちいずれかを初めに選びます。そして、好きなマスから決めた方向に 1 マス移動することを N-1 回繰り返します。
高橋君は N 個のマス上を移動することになりますが、高橋君が通ったマスに書かれている数字を左から通った順番に並べた整数としてあり得る最大のものを求めてください。
制約
- 1 \le N \le 10
- 1 \le A_{i,j} \le 9
- 入力はすべて整数。
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
出力
答えを出力せよ。
入力例 1
4 1161 1119 7111 1811
出力例 1
9786
高橋君が上から 2 行目、左から 4 列目のマスから出発し、右下に進むことで、通ったマスに書かれた数字を並べ 9786 を作ることができます。 9786 より大きい値を作ることはできないため、9786 が解です。
入力例 2
10 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111
出力例 2
1111111111
32bit整数型に答えが収まるとは限らないことに注意してください。
Score : 200 points
Problem Statement
You are given a positive integer N.
We have a grid with N rows and N columns, where the square at the i-th row from the top and j-th column from the left has a digit A_{i,j} written on it.
Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.
- (N,i) is just above (1,i), and (1,i) is just below (N,i). (1\le i\le N).
- (i,N) is just to the left of (i,1), and (i,1) is just to the right of (i,N). (1\le i\le N).
Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction N-1 times.
In this process, Takahashi visits N squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him.
Constraints
- 1 \le N \le 10
- 1 \le A_{i,j} \le 9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
Output
Print the answer.
Sample Input 1
4 1161 1119 7111 1811
Sample Output 1
9786
If Takahashi starts on the square at the 2-nd row from the top and 4-th column from the left and goes down and to the right, the integer obtained by arranging the digits written on the visited squares will be 9786. It is impossible to make a value greater than 9786, so the answer is 9786.
Sample Input 2
10 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111
Sample Output 2
1111111111
Note that the answer may not fit into a 32-bit integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力してください。
なお、相異なる 2 つの文字列 s = s_1 s_2 \ldots s_n と t = t_1 t_2 \ldots t_m について、それらが以下の条件のいずれかを満たすとき、辞書順で s \lt t であるとします。
- ある整数 i\ (1 \leq i \leq \min(n,m)) が存在し、s_i \lt t_i かつすべての整数 j\ (1 \leq j \lt i) について s_j=t_j
- すべての整数 i\ (1 \leq i \leq \min(n,m)) について s_i = t_i かつ、n \lt m
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力せよ。
入力例 1
aba
出力例 1
aab
S= aba を並び替えて得られる文字列は以下の 3 つが考えられます。
abaaabbaa
この中で辞書順で最小のものは、aab です。
入力例 2
zzzz
出力例 2
zzzz
Score : 200 points
Problem Statement
You are given a string S. Find the lexicographically smallest string S' obtained by permuting the characters of S.
Here, for different two strings s = s_1 s_2 \ldots s_n and t = t_1 t_2 \ldots t_m, s \lt t holds lexicographically when one of the conditions below is satisfied.
- There is an integer i\ (1 \leq i \leq \min(n,m)) such that s_i \lt t_i and s_j=t_j for all integers j\ (1 \leq j \lt i).
- s_i = t_i for all integers i\ (1 \leq i \leq \min(n,m)), and n \lt m.
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 lexicographically smallest string S' obtained by permuting the characters in S.
Sample Input 1
aba
Sample Output 1
aab
Three strings can be obtained by permuting aba:
abaaabbaa
The lexicographically smallest among them is aab.
Sample Input 2
zzzz
Sample Output 2
zzzz
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoderレストランでは 1 から N までの番号がつけられている N 種類の食材を扱っています。
また、AtCoderレストランでは 1 から M までの番号がつけられている M 個の料理を提供しています。料理 i には K_i 種類の食材が使われており、食材 A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} が使われています。
すぬけくんは現在 N 種類の食材がすべて苦手です。また、すぬけ君は苦手な食材が 1 種類でも使われている料理を食べることができず、苦手な食材が 1 種類も使われていない料理を食べることができます。
すぬけ君はこれから N 日間かけて苦手な食材を克服しようとしています。 すぬけ君は i 日目に食材 B_i を克服し、それ以降苦手な食材でなくなります。
i=1,2,\ldots,N について以下の値を求めてください。
- i 日目にすぬけ君が食材 B_i を克服した直後、すぬけ君が食べることができるAtCoderレストランの料理の個数
制約
- 1 \leq N \leq 3 \times 10^{5}
- 1 \leq M \leq 3 \times 10^{5}
- 1 \leq K_i \leq N (1 \leq i \leq M)
- K_i の総和は 3 \times 10^{5} 以下
- 1 \leq A_{i,j} \leq N (1 \leq i \leq M, 1 \leq j \leq K_i)
- A_{i,j} \neq A_{i,k} (1 \leq i \leq M, j \neq k)
- 1 \leq B_i \leq N (1 \leq i \leq N)
- B_i \neq B_j (i \neq j )
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
K_M A_{M,1} A_{M,2} \ldots A_{M,K_M}
B_1 B_2 \ldots B_N
出力
N 行出力せよ。k 行目には、i=k のときの値を出力せよ。
入力例 1
5 4 2 1 2 3 3 4 5 3 1 2 5 1 3 1 3 2 5 4
出力例 1
0 1 2 3 4
以下のようにすぬけ君は苦手な食材を克服します。
- 1 日目: 食材 1 を克服する。このとき、どの料理にも苦手な食材が使われているため 0 を出力する。
- 2 日目: 食材 3 を克服する。このとき、料理 4 は苦手な食材が使われなくなるため食べられるようになる。料理 4 以外の料理は苦手な食材が使われているため、 1 を出力する。
- 3 日目: 食材 2 を克服する。このとき、料理 1 は苦手な食材が使われなくなるため食べられるようになる。料理 1,4 以外の料理は苦手な食材が使われているため、 2 を出力する。
- 4 日目: 食材 5 を克服する。このとき、料理 3 は苦手な食材が使われなくなるため食べられるようになる。料理 1,3,4 以外の料理は苦手な食材が使われているため、 3 を出力する。
- 5 日目: 食材 4 を克服する。このとき、料理 2 は苦手な食材が使われなくなるため食べられるようになる。全ての料理に苦手な食材が使われていないため、 4 を出力する。
入力例 2
9 8 1 4 5 6 9 7 4 3 4 2 4 1 3 1 1 5 7 9 8 1 5 2 9 8 1 2 1 1 6 5 2 7 8 4 1 9 3
出力例 2
0 0 1 1 1 2 4 6 8
Score : 300 points
Problem Statement
The AtCoder Restaurant uses N types of ingredients numbered from 1 to N.
The restaurant offers M dishes numbered from 1 to M. Dish i uses K_i types of ingredients, namely A_{i,1}, A_{i,2}, \ldots, A_{i,K_i}.
Snuke currently dislikes all N ingredients. He cannot eat any dish that uses one or more ingredients he dislikes, and he can eat a dish that uses none of the disliked ingredients.
Over the next N days, he will overcome his dislikes one ingredient per day. On day i, he overcomes ingredient B_i, and from then on he no longer dislikes it.
For each i=1,2,\ldots,N, find:
- the number of dishes at the AtCoder Restaurant that he can eat immediately after overcoming ingredient B_i on day i.
Constraints
- 1 \leq N \leq 3 \times 10^{5}
- 1 \leq M \leq 3 \times 10^{5}
- 1 \leq K_i \leq N (1 \leq i \leq M)
- The sum of K_i is at most 3 \times 10^{5}.
- 1 \leq A_{i,j} \leq N (1 \leq i \leq M, 1 \leq j \leq K_i)
- A_{i,j} \neq A_{i,k} (1 \leq i \leq M, j \neq k)
- 1 \leq B_i \leq N (1 \leq i \leq N)
- 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 M
K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
K_M A_{M,1} A_{M,2} \ldots A_{M,K_M}
B_1 B_2 \ldots B_N
Output
Print N lines. The k-th line should contain the answer for i=k.
Sample Input 1
5 4 2 1 2 3 3 4 5 3 1 2 5 1 3 1 3 2 5 4
Sample Output 1
0 1 2 3 4
Snuke overcomes his disliked ingredients as follows:
- Day 1: He overcomes ingredient 1. At this time, every dish still uses a disliked ingredient, so print 0.
- Day 2: He overcomes ingredient 3. Dish 4 no longer uses any disliked ingredient and becomes edible; all other dishes still use disliked ingredients, so print 1.
- Day 3: He overcomes ingredient 2. Dish 1 no longer uses any disliked ingredient and becomes edible; all dishes except 1 and 4 still use disliked ingredients, so print 2.
- Day 4: He overcomes ingredient 5. Dish 3 no longer uses any disliked ingredient and becomes edible; all dishes except 1, 3, and 4 still use disliked ingredients, so print 3.
- Day 5: He overcomes ingredient 4. Dish 2 no longer uses any disliked ingredient and becomes edible; now all dishes have no disliked ingredients, so print 4.
Sample Input 2
9 8 1 4 5 6 9 7 4 3 4 2 4 1 3 1 1 5 7 9 8 1 5 2 9 8 1 2 1 1 6 5 2 7 8 4 1 9 3
Sample Output 2
0 0 1 1 1 2 4 6 8