Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
体力が A の敵がいます。あなたは、1 回攻撃をすることで敵の体力を B 減らすことが出来ます。
敵の体力を 0 以下にするためには、最小で何回攻撃をする必要があるでしょうか?
制約
- 1 \le A,B \le 10^{18}
- A, B は整数である。
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
7 3
出力例 1
3
3 回攻撃すると敵の体力が -2 となります。
2 回攻撃しただけでは敵の体力は 1 であるため、3 回攻撃する必要があります。
入力例 2
123456789123456789 987654321
出力例 2
124999999
入力例 3
999999999999999998 2
出力例 3
499999999999999999
Score : 100 points
Problem Statement
There is an enemy with stamina A. Every time you attack the enemy, its stamina reduces by B.
At least how many times do you need to attack the enemy to make its stamina 0 or less?
Constraints
- 1 \le A,B \le 10^{18}
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
7 3
Sample Output 1
3
Attacking three times make the enemy's stamina -2.
Attacking only twice makes the stamina 1, so you need to attack it three times.
Sample Input 2
123456789123456789 987654321
Sample Output 2
124999999
Sample Input 3
999999999999999998 2
Sample Output 3
499999999999999999
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
100 以上 999 以下の整数 S が与えられます。
S が 200 以上 299 以下のとき Success 、そうでないとき Failure と出力してください。
制約
- 100\leq S\leq999
- S は整数
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
200
出力例 1
Success
200 は 200 以上 299 以下なので、Success と出力してください。
入力例 2
401
出力例 2
Failure
401 は 200 以上 299 以下ではないので、Failure と出力してください。
入力例 3
999
出力例 3
Failure
Score : 100 points
Problem Statement
You are given an integer S between 100 and 999 (inclusive).
If S is between 200 and 299 (inclusive), print Success; otherwise, print Failure.
Constraints
- 100 \le S \le 999
- S is an integer.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
200
Sample Output 1
Success
200 is between 200 and 299, so print Success.
Sample Input 2
401
Sample Output 2
Failure
401 is not between 200 and 299, so print Failure.
Sample Input 3
999
Sample Output 3
Failure
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 種類の文字列 S _ 1,S _ 2,\ldots,S _ N が与えられます。
あなたは、次の操作を 1 度だけ行います。
- 相異なる整数 i,j\ (1\le i\le N,1\le j\le N) を選び、S _ i と S _ j をこの順で連結する。
この操作で連結した結果の文字列としてありえるものは何通りあるか求めてください。
選んだ (i,j) が異なっても、連結した文字列が同じ場合は 1 通りと数えることに注意してください。
制約
- 2\le N\le100
- N は整数
- S _ i は英小文字からなる長さ 1 以上 10 以下の文字列
- S _ i\ne S _ j\ (1\le i\lt j\le N)
入力
入力は以下の形式で標準入力から与えられる。
N S _ 1 S _ 2 \vdots S _ N
出力
操作の結果できる文字列が何通りあるかを出力せよ。
入力例 1
4 at atco coder der
出力例 1
11
できる文字列は、atatco, atcoat, atcoder, atcocoder, atder, coderat, coderatco, coderder, derat, deratco, dercoder の 11 通りです。
よって、11 を出力してください。
入力例 2
5 a aa aaa aaaa aaaaa
出力例 2
7
できる文字列は、aaa, aaaa, aaaaa, aaaaaa, aaaaaaa, aaaaaaaa, aaaaaaaaa の 7 通りです。
よって、7 を出力してください。
入力例 3
10 armiearggc ukupaunpiy cogzmjmiob rtwbvmtruq qapfzsitbl vhkihnipny ybonzypnsn esxvgoudra usngxmaqpt yfseonwhgp
出力例 3
90
Score : 200 points
Problem Statement
You are given N types of strings S_1,S_2,\ldots,S_N.
You perform the following operation once:
- Choose distinct integers i and j\ (1\le i\le N,1\le j\le N) and concatenate S_i and S_j in this order.
How many different strings can be obtained as a result of this operation?
If different choices of (i,j) result in the same concatenated string, it is counted as one string.
Constraints
- 2\le N\le100
- N is an integer.
- S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters.
- S_i\ne S_j\ (1\le i\lt j\le N)
Input
The input is given from standard input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the number of different strings that can be obtained from the operation.
Sample Input 1
4 at atco coder der
Sample Output 1
11
The possible strings are atatco, atcoat, atcoder, atcocoder, atder, coderat, coderatco, coderder, derat, deratco, dercoder, which are 11 strings.
Thus, print 11.
Sample Input 2
5 a aa aaa aaaa aaaaa
Sample Output 2
7
The possible strings are aaa, aaaa, aaaaa, aaaaaa, aaaaaaa, aaaaaaaa, aaaaaaaaa, which are 7 strings.
Thus, print 7.
Sample Input 3
10 armiearggc ukupaunpiy cogzmjmiob rtwbvmtruq qapfzsitbl vhkihnipny ybonzypnsn esxvgoudra usngxmaqpt yfseonwhgp
Sample Output 3
90
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder 商店には N 個の商品があります。 i\ (1\leq i\leq N) 番目の商品の価格は P _ i です。 i\ (1\leq i\leq N) 番目の商品は C _ i 個の機能をもち、i\ (1\leq i\leq N) 番目の商品の j\ (1\leq j\leq C _ i) 番目の機能は 1 以上 M 以下の整数 F _ {i,j} として表されます。
高橋くんは、AtCoder 商店の商品で一方が一方の上位互換であるものがないか気になりました。
i 番目の商品と j 番目の商品 (1\leq i,j\leq N) であって、次の条件をすべて満たすものがあるとき Yes と、ないとき No と出力してください。
- P _ i\geq P _ j である。
- j 番目の製品は i 番目の製品がもつ機能をすべてもつ。
- P _ i\gt P _ j であるか、j 番目の製品は i 番目の製品にない機能を 1 つ以上もつ。
制約
- 2\leq N\leq100
- 1\leq M\leq100
- 1\leq P _ i\leq10^5\ (1\leq i\leq N)
- 1\leq C _ i\leq M\ (1\leq i\leq N)
- 1\leq F _ {i,1}\lt F _ {i,2}\lt\cdots\lt F _ {i,C _ i}\leq M\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
P _ 1 C _ 1 F _ {1,1} F _ {1,2} \ldots F _ {1,C _ 1}
P _ 2 C _ 2 F _ {2,1} F _ {2,2} \ldots F _ {2,C _ 2}
\vdots
P _ N C _ N F _ {N,1} F _ {N,2} \ldots F _ {N,C _ N}
出力
答えを 1 行で出力せよ。
入力例 1
5 6 10000 2 1 3 15000 3 1 2 4 30000 3 1 3 5 35000 2 1 5 100000 6 1 2 3 4 5 6
出力例 1
Yes
(i,j)=(4,3) とすると、条件を全て満たします。
他の組は条件を満たしません。例えば (i,j)=(4,5) とすると j 番目の商品は i 番目の商品の機能をすべてもっていますが、P _ i\lt P _ j なので上位互換ではありません。
入力例 2
4 4 3 1 1 3 1 2 3 1 2 4 2 2 3
出力例 2
No
まったく同じ価格と機能をもった商品がある場合もあります。
入力例 3
20 10 72036 3 3 4 9 7716 4 1 2 3 6 54093 5 1 6 7 8 10 25517 7 3 4 5 6 7 9 10 96930 8 2 3 4 6 7 8 9 10 47774 6 2 4 5 6 7 9 36959 5 1 3 4 5 8 46622 7 1 2 3 5 6 8 10 34315 9 1 3 4 5 6 7 8 9 10 54129 7 1 3 4 6 7 8 9 4274 5 2 4 7 9 10 16578 5 2 3 6 7 9 61809 4 1 2 4 5 1659 5 3 5 6 9 10 59183 5 1 2 3 4 9 22186 4 3 5 6 8 98282 4 1 4 7 10 72865 8 1 2 3 4 6 8 9 10 33796 6 1 3 5 7 9 10 74670 4 1 2 6 8
出力例 3
Yes
Score : 200 points
Problem Statement
AtCoder Shop has N products. The price of the i-th product (1\leq i\leq N) is P _ i. The i-th product (1\leq i\leq N) has C_i functions. The j-th function (1\leq j\leq C _ i) of the i-th product (1\leq i\leq N) is represented as an integer F _ {i,j} between 1 and M, inclusive.
Takahashi wonders whether there is a product that is strictly superior to another.
If there are i and j (1\leq i,j\leq N) such that the i-th and j-th products satisfy all of the following conditions, print Yes; otherwise, print No.
- P _ i\geq P _ j.
- The j-th product has all functions of the i-th product.
- P _ i\gt P _ j, or the j-th product has one or more functions that the i-th product lacks.
Constraints
- 2\leq N\leq100
- 1\leq M\leq100
- 1\leq P _ i\leq10^5\ (1\leq i\leq N)
- 1\leq C _ i\leq M\ (1\leq i\leq N)
- 1\leq F _ {i,1}\lt F _ {i,2}\lt\cdots\lt F _ {i,C _ i}\leq M\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
P _ 1 C _ 1 F _ {1,1} F _ {1,2} \ldots F _ {1,C _ 1}
P _ 2 C _ 2 F _ {2,1} F _ {2,2} \ldots F _ {2,C _ 2}
\vdots
P _ N C _ N F _ {N,1} F _ {N,2} \ldots F _ {N,C _ N}
Output
Print the answer in a single line.
Sample Input 1
5 6 10000 2 1 3 15000 3 1 2 4 30000 3 1 3 5 35000 2 1 5 100000 6 1 2 3 4 5 6
Sample Output 1
Yes
(i,j)=(4,3) satisfies all of the conditions.
No other pair satisfies them. For instance, for (i,j)=(4,5), the j-th product has all functions of the i-th one, but P _ i\lt P _ j, so it is not strictly superior.
Sample Input 2
4 4 3 1 1 3 1 2 3 1 2 4 2 2 3
Sample Output 2
No
Multiple products may have the same price and functions.
Sample Input 3
20 10 72036 3 3 4 9 7716 4 1 2 3 6 54093 5 1 6 7 8 10 25517 7 3 4 5 6 7 9 10 96930 8 2 3 4 6 7 8 9 10 47774 6 2 4 5 6 7 9 36959 5 1 3 4 5 8 46622 7 1 2 3 5 6 8 10 34315 9 1 3 4 5 6 7 8 9 10 54129 7 1 3 4 6 7 8 9 4274 5 2 4 7 9 10 16578 5 2 3 6 7 9 61809 4 1 2 4 5 1659 5 3 5 6 9 10 59183 5 1 2 3 4 9 22186 4 3 5 6 8 98282 4 1 4 7 10 72865 8 1 2 3 4 6 8 9 10 33796 6 1 3 5 7 9 10 74670 4 1 2 6 8
Sample Output 3
Yes
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は全 10^9 巻の漫画『すぬけ君』を読むことにしました。
初め、高橋君は『すぬけ君』の単行本を N 冊持っています。i 番目の単行本は a_i 巻です。
高橋君は『すぬけ君』を読み始める前に限り次の操作を 0 回以上何度でも繰り返せます。
- 現在持っている単行本が 1 冊以下の場合、何もしない。そうでない場合、現在持っている単行本から 2 冊を選んで売り、代わりに好きな巻を選んで 1 冊買う
その後、高橋君は『すぬけ君』を 1 巻、2 巻、3 巻、\ldots と順番に読みます。ただし、次に読むべき巻を持っていない状態になった場合、(他の巻を持っているかどうかに関わらず)その時点で『すぬけ君』を読むのをやめます。
高橋君が『すぬけ君』を最大で何巻まで読めるかを求めてください。ただし、1 巻を読めない場合の答えは 0 とします。
制約
- 1 \leq N \leq 3 \times 10^5
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
6 1 2 4 6 7 271
出力例 1
4
『すぬけ君』を読み始める前に「7 巻と 271 巻を選んで売り、代わりに 3 巻を選んで 1 冊買う」という内容で操作をすると、高橋君は 1 巻、2 巻、3 巻、4 巻、6 巻を 1 冊ずつ持っている状態になります。
この状態から『すぬけ君』を読み始めると、高橋君は 1 巻、2 巻、3 巻、4 巻を読み、続いて 5 巻を読もうとしますが持っていないためこの時点で『すぬけ君』を読むのをやめます。
操作の方法を変えても 5 巻を読むことは出来ないため、4 が答えです。
入力例 2
10 1 1 1 1 1 1 1 1 1 1
出力例 2
5
高橋君は同じ巻を 2 冊以上持っているかもしれません。
この入力に対しては以下のように 4 回操作をしてから『すぬけ君』を読み始めることで 5 巻まで読むことが出来、これが最大です。
- 1 巻を 2 冊選んで売り、代わりに 2 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 3 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 4 巻を選んで 1 冊買う
- 1 巻を 2 冊選んで売り、代わりに 5 巻を選んで 1 冊買う
入力例 3
1 5
出力例 3
0
高橋君は 1 巻を読めません。
Score : 300 points
Problem Statement
Takahashi is going to read a manga series "Snuke-kun" in 10^9 volumes.
Initially, Takahashi has N books of this series. The i-th book is Volume a_i.
Takahashi may repeat the following operation any number of (possibly zero) times only before he begins to read:
- Do nothing if he has 1 or less books; otherwise, sell two of the books he has and buy one book of any volume instead.
Then, Takahashi reads Volume 1, Volume 2, Volume 3, \ldots, in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).
Find the latest volume of the series that he can read up to. If he cannot read any, let the answer be 0.
Constraints
- 1 \leq N \leq 3 \times 10^5
- 1 \leq a_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N a_1 \ldots a_N
Output
Print the answer.
Sample Input 1
6 1 2 4 6 7 271
Sample Output 1
4
Before he begins to read the series, he may do the following operation: "sell books of Volumes 7 and 271 and buy one book of Volume 3 instead." Then, he has one book each of Volumes 1, 2, 3, 4, and 6.
If he then begins to read the series, he reads Volumes 1, 2, 3, and 4, then tries to read Volume 5. However, he does not have one, so he stops reading at this point.
Regardless of the choices in the operation, he cannot read Volume 5, so the answer is 4.
Sample Input 2
10 1 1 1 1 1 1 1 1 1 1
Sample Output 2
5
Takahashi may have multiple books of the same volume.
For this input, if he performs the following 4 operations before he begins to read the series, he can read up to Volume 5, which is the maximum:
- Sell two books of Volume 1 and buy a book of Volume 2 instead.
- Sell two books of Volume 1 and buy a book of Volume 3 instead.
- Sell two books of Volume 1 and buy a book of Volume 4 instead.
- Sell two books of Volume 1 and buy a book of Volume 5 instead.
Sample Input 3
1 5
Sample Output 3
0
Takahashi cannot read Volume 1.