Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さが奇数の文字列 S が与えられます。
S の中央の文字を出力してください。
中央の文字とは
ある長さが奇数の文字列 T について、 T の長さを |T| として、T の前から \frac{|T|+1}{2} 番目の文字を中央の文字とします。制約
- S は英小文字からなる長さが奇数の文字列
- S の長さは 1 以上 99 以下
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder
出力例 1
o
atcoder の中央の文字は o です。
入力例 2
a
出力例 2
a
Score : 100 points
Problem Statement
You are given an odd-length string S consisting of lowercase English letters.
Print the central character of S.
What is the central character?
For an odd-length string T, its central character is the \frac{|T|+1}{2}-th character from the beginning, where |T| is the length of T.Constraints
- S is an odd-length string consisting of lowercase English letters.
- The length of S is between 1 and 99 (inclusive).
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder
Sample Output 1
o
The central character of atcoder is o.
Sample Input 2
a
Sample Output 2
a
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1583 以上 2023 以下の整数 Y が与えられます。
西暦 Y 年の日数を求めてください。
なお、制約の範囲内では西暦 Y 年の日数は以下の通りです。
-
Y が 4 の倍数でない年は 365 日
-
Y が 4 の倍数で、かつ 100 の倍数でない年は 366 日
-
Y が 100 の倍数で、かつ 400 の倍数でない年は 365 日
-
Y が 400 の倍数である年は 366 日
制約
- Y は 1583 以上 2023 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
Y
出力
西暦 Y 年の日数を整数として出力せよ。
入力例 1
2023
出力例 1
365
2023 は 4 の倍数でないので 365 日です。
入力例 2
1992
出力例 2
366
1992 は 4 の倍数で、かつ 100 の倍数でないので 366 日です。
入力例 3
1800
出力例 3
365
1800 は 100 の倍数で、かつ 400 の倍数でないので 365 日です。
入力例 4
1600
出力例 4
366
1600 は 400 の倍数なので 366 日です。
Score : 100 points
Problem Statement
You are given an integer Y between 1583 and 2023.
Find the number of days in the year Y of the Gregorian calendar.
Within the given range, the year Y has the following number of days:
-
if Y is not a multiple of 4, then 365 days;
-
if Y is a multiple of 4 but not a multiple of 100, then 366 days;
-
if Y is a multiple of 100 but not a multiple of 400, then 365 days;
-
if Y is a multiple of 400, then 366 days.
Constraints
- Y is an integer between 1583 and 2023, inclusive.
Input
The input is given from Standard Input in the following format:
Y
Output
Print the number of days in the year Y as an integer.
Sample Input 1
2023
Sample Output 1
365
2023 is not a multiple of 4, so it has 365 days.
Sample Input 2
1992
Sample Output 2
366
1992 is a multiple of 4 but not a multiple of 100, so it has 366 days.
Sample Input 3
1800
Sample Output 3
365
1800 is a multiple of 100 but not a multiple of 400, so it has 365 days.
Sample Input 4
1600
Sample Output 4
366
1600 is a multiple of 400, so it has 366 days.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
座標平面上に N 枚の長方形のシートが張られています。
各シートが覆う長方形領域の各辺はそれぞれ x 軸または y 軸と平行であり、
具体的には、i 枚目のシートはちょうど A_i \leq x\leq B_i かつ C_i \leq y\leq D_i をみたす領域全体を覆っています。
1 枚以上のシートによって覆われている領域 の面積を S とすると、
S は制約の条件下で整数となる事が証明できます。
S を整数の形で出力してください。
制約
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
出力
1 枚以上のシートによって覆われている領域の面積 S を整数で出力せよ。
入力例 1
3 0 5 1 3 1 4 0 5 2 5 2 4
出力例 1
20
3 枚のシートによって覆われている領域は次のようになります。
ここで、赤色・黄色・青色はそれぞれ 1 枚目・ 2 枚目・ 3 枚目のシートによって覆われている領域を表しています。

よって、1 枚以上のシートによって覆われている領域の面積は S=20 となります。
入力例 2
2 0 100 0 100 0 100 0 100
出力例 2
10000
異なるシートが同じ領域を覆っている事があることに注意してください。
入力例 3
3 0 1 0 1 0 3 0 5 5 10 0 10
出力例 3
65
Score : 200 points
Problem Statement
There are N rectangular sheets spread out on a coordinate plane.
Each side of the rectangular region covered by each sheet is parallel to the x- or y-axis.
Specifically, the i-th sheet covers exactly the region satisfying A_i \leq x\leq B_i and C_i \leq y\leq D_i.
Let S be the area of the region covered by one or more sheets. It can be proved that S is an integer under the constraints.
Print S as an integer.
Constraints
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
Output
Print the area S of the region covered by one or more sheets as an integer.
Sample Input 1
3 0 5 1 3 1 4 0 5 2 5 2 4
Sample Output 1
20
The three sheets cover the following regions.
Here, red, yellow, and blue represent the regions covered by the first, second, and third sheets, respectively.

Therefore, the area of the region covered by one or more sheets is S=20.
Sample Input 2
2 0 100 0 100 0 100 0 100
Sample Output 2
10000
Note that different sheets may cover the same region.
Sample Input 3
3 0 1 0 1 0 3 0 5 5 10 0 10
Sample Output 3
65
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は座標平面上で龍を操作するゲームを作成しました。
龍は 1 から N までの番号がついた N 個のパーツからなり、パーツ 1 を頭 と呼びます。
最初パーツ i は座標 (i,0) にあります。以下のクエリを Q 個処理してください。
1 C: 頭を方向 C に 1 移動させる。ここで、C はR,L,U,Dのいずれかであり、それぞれ x 軸正方向、x 軸負方向、y 軸正方向、y 軸負方向を意味する。頭以外の全てのパーツは前のパーツに追従するように動く。すなわち、パーツ i\ \ (2\leq i \leq N) は移動前にパーツ i-1 があった座標に移動する。2 p: パーツ p のある座標を求める。
制約
- 2 \leq N \leq 10^6
- 1 \leq Q \leq 2\times 10^5
- 1 種類目のクエリにおいて、C は
R,L,U,Dのいずれか - 2 種類目のクエリにおいて、1\leq p \leq N
- 入力に含まれる数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
各クエリは以下の 2 種類のいずれかの形式である。
1 C
2 p
出力
2 種類目のクエリの回数を q として q 行出力せよ。
i 行目には、i 番目のそのようなクエリに対する答えの座標を (x,y) としたとき、x,y を空白区切りで出力せよ。
入力例 1
5 9 2 3 1 U 2 3 1 R 1 D 2 3 1 L 2 1 2 5
出力例 1
3 0 2 0 1 1 1 0 1 0
2 種類目のクエリを処理する各タイミングにおいて、パーツの位置は次のようになっています。

複数のパーツが同じ座標に存在しうることに注意してください。
Score : 300 points
Problem Statement
Takahashi has created a game where the player controls a dragon on a coordinate plane.
The dragon consists of N parts numbered 1 to N, with part 1 being called the head.
Initially, part i is located at the coordinates (i,0). Process Q queries as follows.
1 C: Move the head by 1 in direction C. Here, C is one ofR,L,U, andD, which represent the positive x-direction, negative x-direction, positive y-direction, and negative y-direction, respectively. Each part other than the head moves to follow the part in front of it. That is, part i (2\leq i \leq N) moves to the coordinates where part i-1 was before the move.2 p: Find the coordinates of part p.
Constraints
- 2 \leq N \leq 10^6
- 1 \leq Q \leq 2\times 10^5
- For the first type of query, C is one of
R,L,U, andD. - For the second type of query, 1\leq p \leq N.
- All numerical input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Each query is in one of the following two formats:
1 C
2 p
Output
Print q lines, where q is the number of queries of the second type.
The i-th line should contain x and y separated by a space, where (x,y) are the answer to the i-th such query.
Sample Input 1
5 9 2 3 1 U 2 3 1 R 1 D 2 3 1 L 2 1 2 5
Sample Output 1
3 0 2 0 1 1 1 0 1 0
At each time when processing the second type of query, the parts are at the following positions:

Note that multiple parts may exist at the same coordinates.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
xy 平面上に 1 から N までの番号が付いた N 個の点があります。
点 i は座標 (X_i,Y_i) にあり、相異なる 2 点は異なる位置に存在します。
この N 点から 3 点を選ぶとき、選ばれた 3 点を線分で結んだ図形が正の面積を持つ三角形になるような点の選び方の総数を求めてください。
制約
- 入力は全て整数である
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
出力
答えを整数として出力せよ。
入力例 1
4 0 1 1 3 1 1 -1 -1
出力例 1
3
点を図示すると、以下のようになります。

三角形をなすような点の選び方は、 \{1,2,3\},\{1,3,4\},\{2,3,4\} の 3 つです。
入力例 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
出力例 2
1124
Score : 300 points
Problem Statement
In the xy-plane, we have N points numbered 1 through N.
Point i is at the coordinates (X_i,Y_i). Any two different points are at different positions.
Find the number of ways to choose three of these N points so that connecting the chosen points with segments results in a triangle with a positive area.
Constraints
- All values in input are integers.
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- (X_i,Y_i) \neq (X_j,Y_j) if i \neq j.
Input
Input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
Output
Print the answer as an integer.
Sample Input 1
4 0 1 1 3 1 1 -1 -1
Sample Output 1
3
The figure below illustrates the points.

There are three ways to choose points that form a triangle: \{1,2,3\},\{1,3,4\},\{2,3,4\}.
Sample Input 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
Sample Output 2
1124
Time Limit: 2.5 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
項数が N の正整数列 A=(a_1,\ldots,a_N) が与えられます。
A の項を 1 個以上選ぶ方法は 2^N-1 通りありますが、そのうち選んだ項の平均値が整数であるものが何通りかを 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 \ldots a_N
出力
答えを出力せよ。
入力例 1
3 2 6 2
出力例 1
6
A の項を選ぶ方法それぞれに対する平均値は以下のようになります。
-
a_1 のみを選んだ場合、平均値は \frac{a_1}{1}=\frac{2}{1} = 2 であり、整数である。
-
a_2 のみを選んだ場合、平均値は \frac{a_2}{1}=\frac{6}{1} = 6 であり、整数である。
-
a_3 のみを選んだ場合、平均値は \frac{a_3}{1}=\frac{2}{1} = 2 であり、整数である。
-
a_1 と a_2 を選んだ場合、平均値は \frac{a_1+a_2}{2}=\frac{2+6}{2} = 4 であり、整数である。
-
a_1 と a_3 を選んだ場合、平均値は \frac{a_1+a_3}{2}=\frac{2+2}{2} = 2 であり、整数である。
-
a_2 と a_3 を選んだ場合、平均値は \frac{a_2+a_3}{2}=\frac{6+2}{2} = 4 であり、整数である。
-
a_1 と a_2 と a_3 を選んだ場合、平均値は \frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3} であり、整数ではない。
以上より、6 通りの選び方が条件を満たします。
入力例 2
5 5 5 5 5 5
出力例 2
31
どのように A の項を 1 個以上選んでも平均値が 5 になります。
Score : 400 points
Problem Statement
You are given a sequence of positive integers A=(a_1,\ldots,a_N) of length N.
There are (2^N-1) ways to choose one or more terms of A. How many of them have an integer-valued average? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 100
- 1 \leq a_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 \ldots a_N
Output
Print the answer.
Sample Input 1
3 2 6 2
Sample Output 1
6
For each way to choose terms of A, the average is obtained as follows:
-
If just a_1 is chosen, the average is \frac{a_1}{1}=\frac{2}{1} = 2, which is an integer.
-
If just a_2 is chosen, the average is \frac{a_2}{1}=\frac{6}{1} = 6, which is an integer.
-
If just a_3 is chosen, the average is \frac{a_3}{1}=\frac{2}{1} = 2, which is an integer.
-
If a_1 and a_2 are chosen, the average is \frac{a_1+a_2}{2}=\frac{2+6}{2} = 4, which is an integer.
-
If a_1 and a_3 are chosen, the average is \frac{a_1+a_3}{2}=\frac{2+2}{2} = 2, which is an integer.
-
If a_2 and a_3 are chosen, the average is \frac{a_2+a_3}{2}=\frac{6+2}{2} = 4, which is an integer.
-
If a_1, a_2, and a_3 are chosen, the average is \frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}, which is not an integer.
Therefore, 6 ways satisfy the condition.
Sample Input 2
5 5 5 5 5 5
Sample Output 2
31
Regardless of the choice of one or more terms of A, the average equals 5.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
1 から N の番号がついた N 人の人が輪になってならんでいます。人 1 の右隣には人 2 が、人 2 の右隣には人 3 が、……、人 N の右隣には人 1 がいます。
N 人の人にそれぞれ 0 以上 M 未満の整数を 1 つずつ渡します。
M^N 通りの渡し方のうち、どの隣り合う 2 人が渡された数も異なるものの数を、998244353 で割ったあまりを求めてください。
制約
- 2 \leq N,M \leq 10^6
- N,M は整数である
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
3 3
出力例 1
6
人 1,2,3 に渡す整数がそれぞれ (0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0) のときの 6 通りです。
入力例 2
4 2
出力例 2
2
人 1,2,3,4 に渡す整数がそれぞれ (0,1,0,1),(1,0,1,0) のときの 2 通りです。
入力例 3
987654 456789
出力例 3
778634319
998244353 で割ったあまりを求めてください。
Score : 475 points
Problem Statement
There are N people numbered from 1 to N standing in a circle. Person 1 is to the right of person 2, person 2 is to the right of person 3, ..., and person N is to the right of person 1.
We will give each of the N people an integer between 0 and M-1, inclusive.
Among the M^N ways to distribute integers, find the number, modulo 998244353, of such ways that no two adjacent people have the same integer.
Constraints
- 2 \leq N,M \leq 10^6
- N and M are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the answer.
Sample Input 1
3 3
Sample Output 1
6
There are six desired ways, where the integers given to persons 1,2,3 are (0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0).
Sample Input 2
4 2
Sample Output 2
2
There are two desired ways, where the integers given to persons 1,2,3,4 are (0,1,0,1),(1,0,1,0).
Sample Input 3
987654 456789
Sample Output 3
778634319
Be sure to find the number modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
1 から N までの番号のついた N 個の区間が与えられます。 区間 i は [L_i,R_i] です。
区間 [l_a,r_a] と区間 [l_b,r_b] は (l_a < l_b < r_a < r_b) または (l_b < l_a < r_b < r_a) を満たすとき、交差するといいます。
f(l,r) を 1 \leq i \leq N を満たし、区間 [l,r] と区間 i が交差する i の個数と定義します。
0 \leq l < r \leq 10^{9} を満たす整数の組 (l,r) において、 f(l,r) の最大値を達成する (l,r) の組のうち l が最小のものを答えてください。そのような組が複数存在する場合はさらにそのうちで r が最小のものを答えてください (0 \leq l < r より、 答えるべき (l,r) の組は一意に定まります)。
制約
- 1 \leq N \leq 10^{5}
- 0 \leq L_i < R_i \leq 10^{9} (1 \leq i \leq N)
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N L_1 R_1 L_2 R_2 \vdots L_N R_N
出力
答えとなる組 (l,r) を次の形式で出力せよ。
l r
入力例 1
5 1 7 3 9 7 18 10 14 15 20
出力例 1
4 11
f(l,r) の最大値は 4 であり、f(l,r)=4 となる (l,r) のうち l の最小値は 4 です。 f(l,r)=4 かつ l=4 を満たす (l,r) は以下の 5 通りです。
- (l,r)=(4,11)
- (l,r)=(4,12)
- (l,r)=(4,13)
- (l,r)=(4,16)
- (l,r)=(4,17)
このうち、r の最小値は 11 であるため、4 と 11 を出力します。
入力例 2
11 856977192 996441446 298251737 935869360 396653206 658841528 710569907 929136831 325371222 425309117 379628374 697340458 835681913 939343451 140179224 887672320 375607390 611397526 93530028 581033295 249611310 775998537
出力例 2
396653207 887672321
Score : 550 points
Problem Statement
You are given N intervals numbered 1 to N. Interval i is [L_i, R_i].
Two intervals [l_a, r_a] and [l_b, r_b] are said to intersect if and only if they satisfy either (l_a < l_b < r_a < r_b) or (l_b < l_a < r_b < r_a).
Define f(l, r) as the number of intervals i (1 \leq i \leq N) that intersect with the interval [l, r].
Among all pairs of integers (l, r) satisfying 0 \leq l < r \leq 10^{9}, find the pair (l, r) that maximizes f(l, r). If there are multiple such pairs, choose the one with the smallest l. If there are still multiple pairs, choose the one with the smallest r among them. (Since 0 \leq l < r, the pair (l, r) to be answered is uniquely determined.)
Constraints
- 1 \leq N \leq 10^{5}
- 0 \leq L_i < R_i \leq 10^{9} (1 \leq i \leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 R_1 L_2 R_2 \vdots L_N R_N
Output
Print the sought pair (l, r) in the following format:
l r
Sample Input 1
5 1 7 3 9 7 18 10 14 15 20
Sample Output 1
4 11
The maximum value of f(l, r) is 4, and among the pairs (l, r) that achieve f(l, r) = 4, the smallest l is 4. The pairs (l, r) that satisfy f(l, r) = 4 and l = 4 are the following five:
- (l, r) = (4, 11)
- (l, r) = (4, 12)
- (l, r) = (4, 13)
- (l, r) = (4, 16)
- (l, r) = (4, 17)
Among these, the smallest r is 11, so print 4 and 11.
Sample Input 2
11 856977192 996441446 298251737 935869360 396653206 658841528 710569907 929136831 325371222 425309117 379628374 697340458 835681913 939343451 140179224 887672320 375607390 611397526 93530028 581033295 249611310 775998537
Sample Output 2
396653207 887672321