Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
明日からの 7 日間の天気予報を表す文字列 S が与えられます。
i 日後の予報は S の i 文字目が o であるとき晴れ、x であるとき雨です。
N 日後の天気予報が晴れかどうかを教えてください。
制約
- N は 1 以上 7 以下の整数
- S は長さ 7 の文字列であり、
oとxのみからなる
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
N 日後の天気予報が晴れであるとき Yes を、雨であるとき No を出力せよ。
入力例 1
4 oooxoox
出力例 1
No
明日からの 7 日間の天気予報は順に、晴れ、晴れ、晴れ、雨、晴れ、晴れ、雨です。
特に、今日から 4 日後の天気予報は雨です。
入力例 2
7 ooooooo
出力例 2
Yes
Score : 100 points
Problem Statement
You are given a string S, which represents a weather forecast for the seven days starting tomorrow.
The i-th of those seven days is forecast to be sunny if the i-th character of S is o, and rainy if that character is x.
Tell us whether the N-th day is forecast to be sunny.
Constraints
- N is an integer between 1 and 7 (inclusive).
- S is a string of length 7 consisting of
oandx.
Input
Input is given from Standard Input in the following format:
N S
Output
Print Yes if the N-th of the seven days starting tomorrow is forecast to be sunny, and No if that day is forecast to be rainy.
Sample Input 1
4 oooxoox
Sample Output 1
No
The forecast for each of the seven days starting tomorrow is as follows: sunny, sunny, sunny, rainy, sunny, sunny, rainy.
In particular, the fourth day is forecast to be rainy.
Sample Input 2
7 ooooooo
Sample Output 2
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
末尾が er または ist であるような文字列 S が与えられます。
S の末尾が er である場合は er を、 ist である場合は ist を出力してください。
制約
- 2 \le |S| \le 20
- S は英小文字のみからなる。
- S の末尾は
erまたはistである。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder
出力例 1
er
S="atcoder" の末尾は er です。
入力例 2
tourist
出力例 2
ist
入力例 3
er
出力例 3
er
Score : 100 points
Problem Statement
You are given a string S ending with er or ist.
If S ends with er, print er; if it ends with ist, print ist.
Constraints
- 2 \le |S| \le 20
- S consists of lowercase English letters.
- S ends with
erorist.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder
Sample Output 1
er
S="atcoder" ends with er.
Sample Input 2
tourist
Sample Output 2
ist
Sample Input 3
er
Sample Output 3
er
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 n の桁和を、 n を十進法で表したときの各桁の和と定めます。例えば 2026 の桁和は 2+0+2+6=10 です。
N 以下の正整数のうち、桁和が K であるものの個数を求めてください。
制約
- 1\leq N,K \leq 10^5
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K
出力
答えを出力せよ。
入力例 1
30 4
出力例 1
3
30 以下の正整数のうち、桁和が 4 であるものは、4,13,22 の 3 個です。
入力例 2
2026 10
出力例 2
121
入力例 3
99999 45
出力例 3
1
Score : 200 points
Problem Statement
The digit sum of a positive integer n is defined as the sum of the digits when n is represented in decimal. For example, the digit sum of 2026 is 2+0+2+6=10.
Find the number of positive integers not exceeding N whose digit sum is K.
Constraints
- 1\leq N,K \leq 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
Output
Output the answer.
Sample Input 1
30 4
Sample Output 1
3
Among the positive integers not exceeding 30, there are three integers whose digit sum is 4: 4,13,22.
Sample Input 2
2026 10
Sample Output 2
121
Sample Input 3
99999 45
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
一直線状の倉庫があります。この倉庫に 偶数個 の荷物が保管されています。
倉庫の情報は文字列 S として与えらます。
倉庫は区画 1,2,\dots,|S| の |S| 個の区画からなり、 S の各文字は以下の情報を表します。
- S の i 文字目が
#であるとき、区画 i に荷物が 1 つ置かれている。 - S の i 文字目が
.であるとき、区画 i に荷物が置かれていない。
この倉庫にはロボットがあり、このロボットは以下の行動を倉庫から荷物が無くなるまで繰り返します。
- 荷物をその荷物がある区画番号の小さい方から 2 つ回収する。回収された荷物は倉庫の外へ運び出される。
繰り返しの各回で運び出された 2 つの荷物が倉庫のどの区画にあったものかを求めてください。
制約
- S は
#と.からなる長さ 2 以上 1000 以下の文字列 - 倉庫には偶数個の荷物が保管されている
- 倉庫には 2 つ以上の荷物が保管されている
入力
入力は以下の形式で標準入力から与えられる。
S
出力
倉庫に保管されている荷物の総数を m とすると、 m/2 行出力せよ。
そのうち i 行目には、 i 回目の繰り返しで運び出された荷物が元々あった区画の番号を小さい方から順に カンマ区切り で出力せよ。
入力例 1
.#.##..##.#.###....#
出力例 1
2,4 5,8 9,11 13,14 15,20
区画 2,4,5,8,9,11,13,14,15,20 に荷物が保管されています。
- 1 回目の繰り返しでは区画 2,4 にあった荷物が運び出されます。
- 2 回目の繰り返しでは区画 5,8 にあった荷物が運び出されます。
- 3 回目の繰り返しでは区画 9,11 にあった荷物が運び出されます。
- 4 回目の繰り返しでは区画 13,14 にあった荷物が運び出されます。
- 5 回目の繰り返しでは区画 15,20 にあった荷物が運び出されます。
Score : 200 points
Problem Statement
There is a linear warehouse, which stores an even number of packages.
The layout of the warehouse is represented by a string S.
The warehouse has |S| sections, numbered 1,2,\dots,|S|, and the string S describes them as follows:
- When the i-th character of S is
#, one package is placed in section i. - When the i-th character of S is
., no package is placed in section i.
The warehouse has a robot, which repeats the following action until there are no more packages in the warehouse:
- Collect two packages from the sections with the smallest section numbers among the sections containing packages. The collected packages are carried out of the warehouse.
For each iteration, determine which sections of the warehouse the two packages that were carried out were originally located.
Constraints
- S is a string consisting of
#and.with length between 2 and 1000, inclusive. - The warehouse stores an even number of packages.
- The warehouse stores at least two packages.
Input
The input is given from Standard Input in the following format:
S
Output
Let m be the total number of packages stored in the warehouse. Output m/2 lines.
The i-th line should contain the section numbers where the packages carried out in the i-th iteration were originally located, in ascending order, separated by a comma.
Sample Input 1
.#.##..##.#.###....#
Sample Output 1
2,4 5,8 9,11 13,14 15,20
Packages are stored in sections 2,4,5,8,9,11,13,14,15,20.
- In the 1st iteration, packages from sections 2,4 are carried out.
- In the 2nd iteration, packages from sections 5,8 are carried out.
- In the 3rd iteration, packages from sections 9,11 are carried out.
- In the 4th iteration, packages from sections 13,14 are carried out.
- In the 5th iteration, packages from sections 15,20 are carried out.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10^9 階建てのビルがあり、N 本のはしごがかかっています。
ビルの 1 階にいる高橋君ははしごを繰り返し使って(0 回でもよい)できるだけ高い階へ上りたいと考えています。
はしごには 1 から N までの番号がついており、はしご i は A_i 階と B_i 階を結んでいます。はしご i を利用すると A_i 階から B_i 階へ、または B_i 階から A_i 階へ双方向に移動することができますが、それ以外の階の間の移動は行うことはできません。
また、高橋君は同じ階での移動は自由に行うことができますが、はしご以外の方法で他の階へ移動することはできません。
高橋君は最高で何階へ上ることができますか?
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9
- A_i \neq B_i
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \ldots A_N B_N
出力
答えを出力せよ。
入力例 1
4 1 4 4 3 4 10 8 3
出力例 1
10
はしご 1 で 4 階に進み、はしご 3 で 10 階に進むことにより、10 階にたどり着くことができます。
入力例 2
6 1 3 1 5 1 12 3 5 3 12 5 12
出力例 2
12
入力例 3
3 500000000 600000000 600000000 700000000 700000000 800000000
出力例 3
1
他の階への移動ができない場合もあります。
Score : 300 points
Problem Statement
There is a 10^9-story building with N ladders.
Takahashi, who is on the 1-st (lowest) floor, wants to reach the highest floor possible by using ladders (possibly none).
The ladders are numbered from 1 to N, and ladder i connects the A_i-th and B_i-th floors. One can use ladder i in either direction to move from the A_i-th floor to the B_i-th floor or vice versa, but not between other floors.
Takahashi can freely move within the same floor, but cannot move between floors without using ladders.
What is the highest floor Takahashi can reach?
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq 10^9
- A_i \neq B_i
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \ldots A_N B_N
Output
Print an integer representing the answer.
Sample Input 1
4 1 4 4 3 4 10 8 3
Sample Output 1
10
He can reach the 10-th floor by using ladder 1 to get to the 4-th floor and then ladder 3 to get to the 10-th floor.
Sample Input 2
6 1 3 1 5 1 12 3 5 3 12 5 12
Sample Output 2
12
Sample Input 3
3 500000000 600000000 600000000 700000000 700000000 800000000
Sample Output 3
1
He may be unable to move between floors.