実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さが偶数の文字列 S が与えられます。S の長さを |S|、S の i 文字目を S_i で表します。
i = 1, 2, \ldots, \frac{|S|}{2} の順に以下の操作を行い、すべての操作を終えた後の S を出力してください。
- S_{2i-1} と S_{2i} を入れ替える
制約
- S は英小文字からなる長さが偶数の文字列
- S の長さは 100 以下
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
abcdef
出力例 1
badcfe
操作を行う前は S = abcdef
です。
i = 1 について操作を行うと、S_1 と S_2 が入れ替わるので S = bacdef
になります。
i = 2 について操作を行うと、S_3 と S_4 が入れ替わるので S = badcef
になります。
i = 3 について操作を行うと、S_5 と S_6 が入れ替わるので S = badcfe
になります。
したがって、badcfe
を出力します。
入力例 2
aaaa
出力例 2
aaaa
入力例 3
atcoderbeginnercontest
出力例 3
taocedbrgeniencrnoetts
Score : 100 points
Problem Statement
You are given a string S of even length consisting of lowercase English letters. Let |S| be the length of S, and S_i be the i-th character of S.
Perform the following operation for each i = 1, 2, \ldots, \frac{|S|}{2} in this order, and print the final S.
- Swap S_{2i-1} and S_{2i}.
Constraints
- S is a string of even length consisting of lowercase English letters.
- The length of S is at most 100.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
abcdef
Sample Output 1
badcfe
Initially, S = abcdef
.
Performing the operation for i = 1 swaps S_1 and S_2, making S = bacdef
.
Performing the operation for i = 2 swaps S_3 and S_4, making S = badcef
.
Performing the operation for i = 3 swaps S_5 and S_6, making S = badcfe
.
Thus, badcfe
should be printed.
Sample Input 2
aaaa
Sample Output 2
aaaa
Sample Input 3
atcoderbeginnercontest
Sample Output 3
taocedbrgeniencrnoetts
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君と青木君はジョギングをすることにしました。
高橋君は「A 秒間秒速 B メートルで歩き、C 秒間休む」ことを繰り返します。
青木君は「D 秒間秒速 E メートルで歩き、F 秒間休む」ことを繰り返します。
二人が同時にジョギングを始めてから X 秒後、高橋君と青木君のうちどちらが長い距離を進んでいますか?
制約
- 1 \leq A, B, C, D, E, F, X \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E F X
出力
二人が同時にジョギングを始めてから X 秒後時点で、高橋君の方が青木君よりも長い距離を進んでいるならば Takahashi
、青木君の方が高橋君よりも長い距離を進んでいるならば Aoki
、二人が同じ距離を進んでいるならば Draw
と出力せよ。
入力例 1
4 3 3 6 2 5 10
出力例 1
Takahashi
二人はジョギングを始めてから 10 秒間の間、以下のように行動します。
- 高橋君は 4 秒間歩き、3 秒間休んだ後、再び 3 秒間歩く。合計 (4 + 3) \times 3 = 21 メートル歩く。
- 青木君は 6 秒間歩き、4 秒間休む。合計 6 \times 2 = 12 メートル歩く。
高橋君の方が長い距離を進んでいるので、Takahashi
と出力します。
入力例 2
3 1 4 1 5 9 2
出力例 2
Aoki
入力例 3
1 1 1 1 1 1 1
出力例 3
Draw
Score : 100 points
Problem Statement
Takahashi and Aoki decided to jog.
Takahashi repeats the following: "walk at B meters a second for A seconds and take a rest for C seconds."
Aoki repeats the following: "walk at E meters a second for D seconds and take a rest for F seconds."
When X seconds have passed since they simultaneously started to jog, which of Takahashi and Aoki goes ahead?
Constraints
- 1 \leq A, B, C, D, E, F, X \leq 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E F X
Output
When X seconds have passed since they simultaneously started to jog, if Takahashi goes ahead of Aoki, print Takahashi
; if Aoki goes ahead of Takahashi, print Aoki
; if they have advanced the same distance, print Draw
.
Sample Input 1
4 3 3 6 2 5 10
Sample Output 1
Takahashi
During the first 10 seconds after they started to jog, they move as follows.
- Takahashi walks for 4 seconds, takes a rest for 3 seconds, and walks again for 3 seconds. As a result, he advances a total of (4 + 3) \times 3 = 21 meters.
- Aoki walks for 6 seconds and takes a rest for 4 seconds. As a result, he advances a total of 6 \times 2 = 12 meters.
Since Takahashi goes ahead, Takahashi
should be printed.
Sample Input 2
3 1 4 1 5 9 2
Sample Output 2
Aoki
Sample Input 3
1 1 1 1 1 1 1
Sample Output 3
Draw
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?
制約
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S, T は整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。
入力例 1
1 0
出力例 1
4
条件を満たす非負整数の組 (a,b,c) は (0,0,0), (0,0,1), (0,1,0), (1,0,0) の 4 つです。
入力例 2
2 5
出力例 2
10
入力例 3
10 10
出力例 3
213
入力例 4
30 100
出力例 4
2471
Score : 200 points
Problem Statement
How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?
Constraints
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S and T are integers.
Input
Input is given from Standard Input in the following format:
S T
Output
Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.
Sample Input 1
1 0
Sample Output 1
4
The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.
Sample Input 2
2 5
Sample Output 2
10
Sample Input 3
10 10
Sample Output 3
213
Sample Input 4
30 100
Sample Output 4
2471
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
長さ M の A の連続部分列 B=(B_1,B_2,\dots,B_M) に対する、\displaystyle \sum_{i=1}^{M} i \times B_i の最大値を求めてください。
注記
数列の連続部分列とは、数列の先頭から 0 個以上、末尾から 0 個以上の要素を削除して得られる列のことをいいます。
例えば (2, 3) や (1, 2, 3) は (1, 2, 3, 4) の連続部分列ですが、(1, 3) や (3,2,1) は (1, 2, 3, 4) の連続部分列ではありません。
制約
- 1 \le M \le N \le 2 \times 10^5
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 2 5 4 -1 8
出力例 1
15
B=(A_3,A_4) とした場合、\displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times (-1) + 2 \times 8 = 15 となります。16 以上の値を達成することはできないため、解は 15 です。
B=(A_1,A_4) などを選ぶことができないことに注意してください。
入力例 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
出力例 2
31
Score : 300 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N.
Find the maximum value of \displaystyle \sum_{i=1}^{M} i \times B_i for a contiguous subarray B=(B_1,B_2,\dots,B_M) of A of length M.
Notes
A contiguous subarray of a number sequence is a sequence that is obtained by removing 0 or more initial terms and 0 or more final terms from the original number sequence.
For example, (2, 3) and (1, 2, 3) are contiguous subarrays of (1, 2, 3, 4), but (1, 3) and (3,2,1) are not contiguous subarrays of (1, 2, 3, 4).
Constraints
- 1 \le M \le N \le 2 \times 10^5
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 2 5 4 -1 8
Sample Output 1
15
When B=(A_3,A_4), we have \displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times (-1) + 2 \times 8 = 15. Since it is impossible to achieve 16 or a larger value, the solution is 15.
Note that you are not allowed to choose, for instance, B=(A_1,A_4).
Sample Input 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
Sample Output 2
31