Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は、毎日 S 時 0 分に部屋の電気をつけ、毎日 T 時 0 分に消します。
電気をつけている間に日付が変わることもあります。
X 時 30 分に部屋の電気がついているかどうか判定してください。
制約
- 0 \leq S, T, X \leq 23
- S \neq T
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T X
出力
X 時 30 分に部屋の電気がついているならば Yes
と、そうでなければ No
と出力せよ。
入力例 1
7 20 12
出力例 1
Yes
部屋の電気がついているのは 7 時 0 分から 20 時 0 分までの間です。12 時 30 分には電気がついているので、Yes
と出力します。
入力例 2
20 7 12
出力例 2
No
部屋の電気がついているのは 0 時 0 分から 7 時 0 分までの間と、20 時 0 分から(次の日の)0 時 0 分までの間です。
12 時 30 分には電気がついていないので、No
と出力します。
入力例 3
23 0 23
出力例 3
Yes
Score : 100 points
Problem Statement
Takahashi turns on the light of his room at S o'clock (on the 24-hour clock) every day and turns it off at T o'clock every day.
The date may change while the light is on.
Determine whether the light is on at 30 minutes past X o'clock.
Constraints
- 0 \leq S, T, X \leq 23
- S \neq T
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
S T X
Output
If the light is on at 30 minutes past X o'clock, print Yes
; otherwise, print No
.
Sample Input 1
7 20 12
Sample Output 1
Yes
The light is on between 7 o'clock and 20 o'clock. At 30 minutes past 12 o'clock, it is on, so we print Yes
.
Sample Input 2
20 7 12
Sample Output 2
No
The light is on between 0 o'clock and 7 o'clock, and between 20 o'clock and 0 o'clock (on the next day). At 30 minutes past 12 o'clock, it is off, so we print No
.
Sample Input 3
23 0 23
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 国の暦では、1 年は 1 月から M 月までの M ヶ月からなり、どの月も 1 日から D 日までの D 日からなります。
AtCoder 国の暦で y 年 m 月 d 日の翌日は何年何月何日であるか求めてください。
制約
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
M D y m d
出力
AtCoder 国の暦で y 年 m 月 d 日の翌日が y' 年 m' 月 d' 日であるとき、y',m',d' をこの順に空白区切りで出力せよ。
入力例 1
12 30 2023 12 30
出力例 1
2024 1 1
AtCoder 国の暦では 1 年は 12 ヶ月であり、どの月も 30 日からなります。 よって、2023 年 12 月 30 日の翌日は 2024 年 1 月 1 日になります。
入力例 2
36 72 6789 23 45
出力例 2
6789 23 46
AtCoder 国の暦では 1 年は 36 ヶ月であり、どの月も 72 日からなります。 よって、6789 年 23 月 45 日の翌日は 6789 年 23 月 46 日になります。
入力例 3
12 30 2012 6 20
出力例 3
2012 6 21
Score : 100 points
Problem Statement
In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.
What day follows year y, month m, day d in this calendar?
Constraints
- 1000 \leq y \leq 9000
- 1 \leq m \leq M \leq 99
- 1 \leq d \leq D \leq 99
- All input values are integers.
Input
The input is given from Standard Input in the following format:
M D y m d
Output
If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.
Sample Input 1
12 30 2023 12 30
Sample Output 1
2024 1 1
In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days. Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.
Sample Input 2
36 72 6789 23 45
Sample Output 2
6789 23 46
In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days. Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.
Sample Input 3
12 30 2012 6 20
Sample Output 3
2012 6 21
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
以下の手順で行われる試験があります。
- 試験は 1 ラウンド目から N ラウンド目までの N ラウンドからなる。
- 各ラウンドに対し、 0 以上 100 以下の整数でスコアが与えられる。
- N ラウンドのスコアのうち、最高スコアと最低スコアを除いた N-2 ラウンドのスコアの合計が最終結果となる。
- 厳密には、各ラウンドのスコアを昇順に並べた列を S=(S_1,S_2,\dots,S_N) としたとき、最終結果は S_2+S_3+\dots+S_{N-1} となる。
現在、試験のうち N-1 ラウンドが終了し、 i ラウンド目のスコアは A_i でした。
最終結果を X 以上とするために N ラウンド目に取るべきスコアの最小値を出力してください。
但し、 N ラウンド目にどのようなスコアを取っても最終結果が X 以上にならない場合、代わりに -1
と出力してください。
なお、 N ラウンド目に取りうるスコアは 0 以上 100 以下の整数であることに注意してください。
制約
- 入力は全て整数
- 3 \le N \le 100
- 0 \le X \le 100 \times (N-2)
- 0 \le A_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 A_2 \dots A_{N-1}
出力
答えを出力せよ。
入力例 1
5 180 40 60 80 50
出力例 1
70
4 ラウンド目までのスコアは 40,60,80,50 でした。
5 ラウンド目にスコア 70 を取ると、スコアを昇順に並べた列は S=(40,50,60,70,80) となり、最終結果は 50+60+70=180 となります。
なお、最終結果を 180 以上にするために取るべきスコアの最小値が 70 であることが示せます。
入力例 2
3 100 100 100
出力例 2
0
2 ラウンド目までのスコアは 100,100 でした。
3 ラウンド目にスコア 0 を取ると、スコアを昇順に並べた列は S=(0,100,100) となり、最終結果は 100 となります。
最大スコアである 100 が複数ありますが、そのうち 1 つしか除かれないことに注意してください。(最小スコアについても同様です)
なお、最終結果を 100 以上にするために取るべきスコアの最小値が 0 であることが示せます。
入力例 3
5 200 0 0 99 99
出力例 3
-1
4 ラウンド目までのスコアは 0,0,99,99 でした。
5 ラウンド目にどのようなスコアを取っても、最終結果を 200 以上にすることができないことが示せます。
入力例 4
10 480 59 98 88 54 70 24 8 94 46
出力例 4
45
Score : 200 points
Problem Statement
There is an exam structured as follows.
- The exam consists of N rounds called round 1 to N.
- In each round, you are given an integer score between 0 and 100, inclusive.
- Your final grade is the sum of the N-2 of the scores earned in the rounds excluding the highest and lowest.
- Formally, let S=(S_1,S_2,\dots,S_N) be the sequence of the scores earned in the rounds sorted in ascending order, then the final grade is S_2+S_3+\dots+S_{N-1}.
Now, N-1 rounds of the exam have ended, and your score in round i was A_i.
Print the minimum score you must earn in round N for a final grade of X or higher.
If your final grade will never be X or higher no matter what score you earn in round N, print -1
instead.
Note that your score in round N can only be an integer between 0 and 100.
Constraints
- All input values are integers.
- 3 \le N \le 100
- 0 \le X \le 100 \times (N-2)
- 0 \le A_i \le 100
Input
The input is given from Standard Input in the following format:
N X A_1 A_2 \dots A_{N-1}
Output
Print the answer.
Sample Input 1
5 180 40 60 80 50
Sample Output 1
70
Your scores in the first four rounds were 40, 60, 80, and 50.
If you earn a score of 70 in round 5, the sequence of the scores sorted in ascending order will be S=(40,50,60,70,80), for a final grade of 50+60+70=180.
It can be shown that 70 is the minimum score you must earn for a final grade of 180 or higher.
Sample Input 2
3 100 100 100
Sample Output 2
0
Your scores in the first two rounds were 100 and 100.
If you earn a score of 0 in round 3, the sequence of the scores sorted in ascending order will be S=(0,100,100), for a final grade of 100.
Note that the highest score, 100, is earned multiple times, and only one of them is excluded. (The same goes for the lowest score.)
It can be shown that 0 is the minimum score you must earn for a final grade of 100 or higher.
Sample Input 3
5 200 0 0 99 99
Sample Output 3
-1
Your scores in the first four rounds were 0, 0, 99, and 99.
It can be shown that your final grade will never be 200 or higher no matter what score you earn in round 5.
Sample Input 4
10 480 59 98 88 54 70 24 8 94 46
Sample Output 4
45
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
配点 : 300 点
問題文
1,2,\dots,N が 1 回ずつ現れる長さ N の数列を「長さ N の順列」と呼びます。
長さ N の順列 P = (p_1, p_2,\dots,p_N) が与えられるので、以下の条件を満たす長さ N の順列 Q = (q_1,\dots,q_N) を出力してください。
- 全ての i (1 \leq i \leq N) に対して Q の p_i 番目の要素が i である。
ただし、条件を満たす Q は必ずただ 1 つ存在することが証明できます。
制約
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) は長さ N の順列である。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N p_1 p_2 \dots p_N
出力
数列 Q を空白区切りで 1 行で出力せよ。
q_1 q_2 \dots q_N
入力例 1
3 2 3 1
出力例 1
3 1 2
以下に説明する通り、 Q=(3,1,2) は条件を満たす順列です。
- i = 1 のとき p_i = 2, q_2 = 1
- i = 2 のとき p_i = 3, q_3 = 2
- i = 3 のとき p_i = 1, q_1 = 3
入力例 2
3 1 2 3
出力例 2
1 2 3
全ての i (1 \leq i \leq N) に対して p_i = i が成り立つときは P = Q になります。
入力例 3
5 5 3 2 4 1
出力例 3
5 3 2 4 1
Score : 300 points
Problem Statement
We will call a sequence of length N where each of 1,2,\dots,N occurs once as a permutation of length N.
Given a permutation of length N, P = (p_1, p_2,\dots,p_N), print a permutation of length N, Q = (q_1,\dots,q_N), that satisfies the following condition.
- For every i (1 \leq i \leq N), the p_i-th element of Q is i.
It can be proved that there exists a unique Q that satisfies the condition.
Constraints
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) is a permutation of length N (defined in Problem Statement).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_1 p_2 \dots p_N
Output
Print the sequence Q in one line, with spaces in between.
q_1 q_2 \dots q_N
Sample Input 1
3 2 3 1
Sample Output 1
3 1 2
The permutation Q=(3,1,2) satisfies the condition, as follows.
- For i = 1, we have p_i = 2, q_2 = 1.
- For i = 2, we have p_i = 3, q_3 = 2.
- For i = 3, we have p_i = 1, q_1 = 3.
Sample Input 2
3 1 2 3
Sample Output 2
1 2 3
If p_i = i for every i (1 \leq i \leq N), we will have P = Q.
Sample Input 3
5 5 3 2 4 1
Sample Output 3
5 3 2 4 1