Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君はティーポットです。
高橋君はティーポットなので、紅茶なら喜んで受け入れますが、それ以外の液体を入れようとすると拒否してしまいます。
高橋君に S という名前の液体を入れることが出来るか判定してください。
英小文字からなる長さ N の文字列 S が与えられます。
S が tea で終わる文字列であるかどうかを判定してください。
制約
- 1 \leq N \leq 20
- N は整数
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S が tea で終わる文字列であれば Yes を、そうでなければ No を出力せよ。
入力例 1
8 greentea
出力例 1
Yes
greentea は tea で終わる文字列です。
入力例 2
6 coffee
出力例 2
No
coffee は tea で終わる文字列ではありません。
入力例 3
3 tea
出力例 3
Yes
入力例 4
1 t
出力例 4
No
Score : 100 points
Problem Statement
Takahashi is a teapot.
Since he is a teapot, he will gladly accept tea, but will refuse any other liquid.
Determine whether you can pour a liquid named S into him.
You are given a string S of length N consisting of lowercase English letters.
Determine whether S is a string that ends with tea.
Constraints
- 1 \leq N \leq 20
- N is an integer.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
If S is a string that ends with tea, print Yes; otherwise, print No.
Sample Input 1
8 greentea
Sample Output 1
Yes
greentea is a string that ends with tea.
Sample Input 2
6 coffee
Sample Output 2
No
coffee is not a string that ends with tea.
Sample Input 3
3 tea
Sample Output 3
Yes
Sample Input 4
1 t
Sample Output 4
No
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
配点 : 200 点
問題文
整数 0 の書かれたカードが 100 枚積み重なったカードの山があります。
Q 個のクエリを処理してください。それぞれのクエリは以下のいずれかです。
- タイプ 1 : 整数 x の書かれたカードを 1 枚カードの山の一番上に積み重ねる。
- タイプ 2 : カードの山の一番上のカードを取り除き、取り除いたカードに書かれている整数を出力する。ここで、本問題の制約下では必ず山にカードが存在する。
制約
- 1\le Q\le 100
- 1\le x\le 100
- タイプ 2 のクエリが 1 つ以上存在する。
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
i 番目のクエリ \text{query}_i では、まずクエリのタイプ c_i (1,2 のいずれか)が与えられる。 c_i=1 の場合はさらに整数 x が追加で与えられる。
すなわち、各クエリは以下に示す 2 つの形式のいずれかである。
1 x
2
出力
c_i=2 を満たすクエリの回数を q として、 q 行出力せよ。
j (1\le j\le q) 行目では j 番目のそのようなクエリに対する答えを出力せよ。
入力例 1
6 2 1 4 1 3 2 2 2
出力例 1
0 3 4 0
各クエリを処理した後の山は順に以下のようになります:
- カードの山の一番上のカードを取り除く。取り除いたカードに書かれた整数は 0 であるため、 0 を出力する。
- カードの山は 0 の書かれたカードが 99 枚となる。
- 4 が書かれたカードを山の上に追加する。
- カードの山は上から順に 4 の書かれたカードが 1 枚、 0 の書かれたカードが 99 枚となる。
- 3 が書かれたカードを山の上に追加する。
- カードの山は上から順に 3 の書かれたカードが 1 枚、 4 の書かれたカードが 1 枚、 0 の書かれたカードが 99 枚となる。
- カードの山の一番上のカードを取り除く。取り除いたカードに書かれた整数は 3 であるため、 3 を出力する。
- カードの山は上から順に 4 の書かれたカードが 1 枚、 0 の書かれたカードが 99 枚となる。
- カードの山の一番上のカードを取り除く。取り除いたカードに書かれた整数は 4 であるため、 4 を出力する。
- カードの山は 0 の書かれたカードが 99 枚となる。
- カードの山の一番上のカードを取り除く。取り除いたカードに書かれた整数は 0 であるため、 0 を出力する。
- カードの山は 0 の書かれたカードが 98 枚となる。
入力例 2
5 2 2 2 2 2
出力例 2
0 0 0 0 0
Score : 200 points
Problem Statement
There is a stack of 100 cards, each labeled with the integer 0.
Process Q queries. Each query is of one of the following:
- Type 1: Place a card labeled with an integer x on top of the stack.
- Type 2: Remove the top card of the stack and output the integer written on that removed card. Under the constraints of this problem, the stack always has at least one card.
Constraints
- 1 \le Q \le 100
- 1 \le x \le 100
- There is at least one query of type 2.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
The i-th query \text{query}_i starts with the query type c_i (1 or 2), followed by the integer x if c_i=1.
That is, each query is in one of the following two formats:
1 x
2
Output
Let q be the number of queries with c_i=2. Print q lines.
The j-th line (1 \le j \le q) should contain the answer to the j-th such query.
Sample Input 1
6 2 1 4 1 3 2 2 2
Sample Output 1
0 3 4 0
After processing each query, the stack is as follows:
- Remove the top card of the stack. The integer on the removed card is 0, so output 0.
- The stack then has 99 cards labeled with 0.
- Add a card labeled 4 on top.
- The stack then has 1 card labeled 4, and 99 cards labeled 0, from top to bottom.
- Add a card labeled 3 on top.
- The stack then has 1 card labeled 3, 1 card labeled 4, and 99 cards labeled 0, from top to bottom.
- Remove the top card. The integer on that card is 3, so output 3.
- The stack then has 1 card labeled 4, and 99 cards labeled 0, from top to bottom.
- Remove the top card. The integer on that card is 4, so output 4.
- The stack then has 99 cards labeled 0.
- Remove the top card. The integer on that card is 0, so output 0.
- The stack then has 98 cards labeled 0.
Sample Input 2
5 2 2 2 2 2
Sample Output 2
0 0 0 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder 国では、1 年が N か月からなる暦を使っています。 i 月 (1\leq i\leq N) は、i 月 1 日から i 月 D _ i 日までの D _ i 日からなります。
AtCoder 国において、1 年のうち日付がゾロ目になる日が何日あるか求めてください。
ただし、i 月 j 日 (1\leq i\leq N,1\leq j\leq D _ i) の日付がゾロ目になるとは、1 種類の数字だけを用いて i と j を十進法で表すことができることをいいます。
制約
- 1\leq N\leq100
- 1\leq D _ i\leq100\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D _ 1 D _ 2 \ldots D _ N
出力
答えを出力せよ。
入力例 1
12 31 29 31 30 31 30 31 31 30 31 30 31
出力例 1
13
AtCoder 国では、 1 月 1 日、1 月 11 日、2 月 2 日、2 月 22 日、3 月 3 日、4 月 4 日、5 月 5 日、6 月 6 日、7 月 7 日、8 月 8 日、9 月 9 日、11 月 1 日、11 月 11 日の合計 13 日の日付がゾロ目になります。
入力例 2
10 10 1 2 3 4 5 6 7 8 100
出力例 2
1
AtCoder 国では、1 月 1 日のみが日付がゾロ目になります。
入力例 3
30 73 8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32
出力例 3
15
Score : 200 points
Problem Statement
AtCoder Kingdom uses a calendar whose year has N months. Month i (1\leq i\leq N) has D _ i days, from day 1 of month i to day D _ i of month i.
How many days in a year of AtCoder have "repdigits" dates?
Here, day j of month i (1\leq i\leq N,1\leq j\leq D _ i) is said to have a repdigit date if and only if all digits in the decimal notations of i and j are the same.
Constraints
- 1\leq N\leq100
- 1\leq D _ i\leq100\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D _ 1 D _ 2 \ldots D _ N
Output
Print the answer.
Sample Input 1
12 31 29 31 30 31 30 31 31 30 31 30 31
Sample Output 1
13
In AtCoder Kingdom, the days that have repdigit dates are January 1, January 11, February 2, February 22, March 3, April 4, May 5, June 6, July 7, August 8, September 9, November 1, and November 11, for a total of 13 days.
Sample Input 2
10 10 1 2 3 4 5 6 7 8 100
Sample Output 2
1
In AtCoder Kingdom, only January 1 has a repdigit date.
Sample Input 3
30 73 8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32
Sample Output 3
15
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N かつ全ての要素が 1 以上 M 以下である整数列のうち、狭義単調増加であるものを全て辞書順に出力してください。
注記
ある 2 個の異なる長さの等しい整数列 A_1,A_2,\dots,A_N と B_1,B_2,\dots,B_N が以下を満たすとき、またその時に限り辞書順で A が B より早いと定義されます。
- ある整数 i(1 \le i \le N) が存在し、1 \le j < i である全ての整数 j に対し A_j=B_j が成り立ち、かつ A_i < B_i が成り立つ。
ある整数列 A_1,A_2,\dots,A_N は以下を満たすとき、またその時に限り狭義単調増加です。
- 全ての整数 i(1 \le i \le N-1) に対し A_i < A_{i+1} が成り立つ。
制約
- 1 \le N \le M \le 10
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
条件を満たす整数列を一行に一つずつ、辞書順に出力せよ(出力例を参考にせよ)。
入力例 1
2 3
出力例 1
1 2 1 3 2 3
条件を満たす数列は (1,2),(1,3),(2,3) の 3 個です。これらを辞書順で早い方から出力します。
入力例 2
3 5
出力例 2
1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5
Score : 300 points
Problem Statement
Print all strictly increasing integer sequences of length N where all elements are between 1 and M (inclusive), in lexicographically ascending order.
Notes
For two integer sequences of the same length A_1,A_2,\dots,A_N and B_1,B_2,\dots,B_N, A is said to be lexicographically earlier than B if and only if:
- there is an integer i (1 \le i \le N) such that A_j=B_j for all integers j satisfying 1 \le j < i, and A_i < B_i.
An integer sequence A_1,A_2,\dots,A_N is said to be strictly increasing if and only if:
- A_i < A_{i+1} for all integers i (1 \le i \le N-1).
Constraints
- 1 \le N \le M \le 10
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
Output
Print the sought sequences in lexicographically ascending order, each in its own line (see Sample Outputs).
Sample Input 1
2 3
Sample Output 1
1 2 1 3 2 3
The sought sequences are (1,2),(1,3),(2,3), which should be printed in lexicographically ascending order.
Sample Input 2
3 5
Sample Output 2
1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5