Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられるので、以下の条件を全て満たす整数 X の個数を 998244353 で割った余りを求めてください。
- N 桁の正整数である。
- X の各桁を上の位から順に X_1,X_2,\dots,X_N とする。このとき以下の条件を全て満たす。
- 全ての整数 1 \le i \le N に対して、 1 \le X_i \le 9
- 全ての整数 1 \le i \le N-1 に対して、 |X_i-X_{i+1}| \le 1
制約
- N は整数
- 2 \le N \le 10^6
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
4
出力例 1
203
4 桁の整数として、例えば 1111,1234,7878,6545 が問題文中の条件を満たします。
入力例 2
2
出力例 2
25
入力例 3
1000000
出力例 3
248860093
998244353 で割った余りを求めることに注意してください。
Score : 300 points
Problem Statement
Given an integer N, find the number of integers X that satisfy all of the following conditions, modulo 998244353.
- X is an N-digit positive integer.
- Let X_1,X_2,\dots,X_N be the digits of X from top to bottom. They satisfy all of the following:
- 1 \le X_i \le 9 for all integers 1 \le i \le N;
- |X_i-X_{i+1}| \le 1 for all integers 1 \le i \le N-1.
Constraints
- N is an integer.
- 2 \le N \le 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
4
Sample Output 1
203
Some of the 4-digit integers satisfying the conditions are 1111,1234,7878,6545.
Sample Input 2
2
Sample Output 2
25
Sample Input 3
1000000
Sample Output 3
248860093
Be sure to find the count modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字からなる文字列 S が与えられます。
S の先頭に a
をいくつか( 0 個でも良い)つけ加えて回文にすることができるか判定してください。
ただし、長さ N の文字列 A=A_1A_2\ldots A_N が回文であるとは、すべての 1\leq i\leq N について A_i=A_{N+1-i} が成り立っていることをいいます。
制約
- 1 \leq \lvert S \rvert \leq 10^6
- S は英小文字のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の先頭に a
をいくつかつけ加えて回文にすることができるならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
kasaka
出力例 1
Yes
kasaka
の先頭に a
を 1 つ付け加えることによって、akasaka
となり回文となるため Yes
を出力します。
入力例 2
atcoder
出力例 2
No
atcoder
の先頭に a
をいくつ付け加えても回文となる事はありません。
入力例 3
php
出力例 3
Yes
php
はそれ自体回文です。S の先頭に付け加える a
は 0 個でも許されるため、Yes
を出力します。
Score : 300 points
Problem Statement
Given is a string S consisting of lowercase English letters.
Determine whether adding some number of a
's (possibly zero) at the beginning of S can make it a palindrome.
Here, a string of length N, A=A_1A_2\ldots A_N, is said to be a palindrome when A_i=A_{N+1-i} for every 1\leq i\leq N.
Constraints
- 1 \leq \lvert S \rvert \leq 10^6
- S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
If adding some number of a
's (possibly zero) at the beginning of S can make it a palindrome, print Yes
; otherwise, print No
.
Sample Input 1
kasaka
Sample Output 1
Yes
By adding one a
at the beginning of kasaka
, we have akasaka
, which is a palindrome, so Yes
should be printed.
Sample Input 2
atcoder
Sample Output 2
No
Adding any number of a
's at the beginning of atcoder
does not make it a palindrome.
Sample Input 3
php
Sample Output 3
Yes
php
itself is a palindrome. Adding zero a
's at the beginning of S is allowed, so Yes
should be printed.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 個の実数の区間が与えられます。i\,(1 \leq i \leq N) 番目の区間は [l_i,r_i] です。i 番目の区間と j 番目の区間が共通部分を持つような組 (i,j)\,(1\leq i < j \leq N) の個数を求めてください。
制約
- 2 \leq N \leq 5 \times 10^5
- 0 \leq l_i < r_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N l_1 r_1 l_2 r_2 \vdots l_N r_N
出力
答えを出力せよ。
入力例 1
3 1 5 7 8 3 7
出力例 1
2
与えられた区間は [1,5], [7,8], [3,7] です。このうち,1 番目と 3 番目、 2 番目と 3 番目の区間が共通部分を持つため、答えは 2 です。
入力例 2
3 3 4 2 5 1 6
出力例 2
3
入力例 3
2 1 2 3 4
出力例 3
0
Score : 400 points
Problem Statement
You are given N intervals of real numbers. The i-th (1 \leq i \leq N) interval is [l_i, r_i]. Find the number of pairs (i, j)\,(1 \leq i < j \leq N) such that the i-th and j-th intervals intersect.
Constraints
- 2 \leq N \leq 5 \times 10^5
- 0 \leq l_i < r_i \leq 10^9
- 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 answer.
Sample Input 1
3 1 5 7 8 3 7
Sample Output 1
2
The given intervals are [1,5], [7,8], [3,7]. Among these, the 1-st and 3-rd intervals intersect, as well as the 2-nd and 3-rd intervals, so the answer is 2.
Sample Input 2
3 3 4 2 5 1 6
Sample Output 2
3
Sample Input 3
2 1 2 3 4
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。A の要素は相異なります。
Q 個のクエリが与えられるので順に処理してください。各クエリは次の 2 種類のどちらかです。
1 x y
: A 内の要素 x の直後に y を挿入する。このクエリが与えられる時点で、A には x が存在することが保証される。2 x
: A 内の要素 x を削除する。このクエリが与えられる時点で、A には x が存在することが保証される。
各クエリの処理後、A は空でなく、要素は相異なることが保証されます。
全てのクエリを処理した後の A を出力してください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- 1 種類目のクエリにおいて、1 \leq x,y \leq 10^9
- 1 種類目のクエリが与えられる時点で、A には x が存在する
- 2 種類目のクエリにおいて、1 \leq x \leq 10^9
- 2 種類目のクエリが与えられる時点で、A には x が存在する
- 各クエリの処理後、A は空でなく、要素は相異なる
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
ここで \mathrm{Query}_i は i 番目のクエリを表し、次の形式で与えられる。
1 x y
2 x
出力
全てのクエリを処理したあとの数列 A を (A_1,\ldots,A_K) とする。A_1,\ldots,A_K をこの順に空白区切りで出力せよ。
入力例 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
出力例 1
4 5 1 3
クエリは次のように処理されます。
- 最初 A=(2,1,4,3) である。
- 1 番目のクエリにより 1 を削除する。A=(2,4,3) となる。
- 2 番目のクエリにより、4 の直後に 5 を挿入する。A=(2,4,5,3) となる。
- 3 番目のクエリにより 2 を削除する。A=(4,5,3) となる。
- 4 番目のクエリにより、5 の直後に 1 を挿入する。A=(4,5,1,3) となる。
入力例 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
出力例 2
5 1 7 2 3
Score: 475 points
Problem Statement
You are given a sequence A=(A_1,\ldots,A_N) of length N. The elements of A are distinct.
Process Q queries in the order they are given. Each query is of one of the following two types:
1 x y
: Insert y immediately after the element x in A. It is guaranteed that x exists in A when this query is given.2 x
: Remove the element x from A. It is guaranteed that x exists in A when this query is given.
It is guaranteed that after processing each query, A will not be empty, and its elements will be distinct.
Print A after processing all the queries.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- For queries of the first type, 1 \leq x,y \leq 10^9.
- When a query of the first type is given, x exists in A.
- For queries of the second type, 1 \leq x \leq 10^9.
- When a query of the second type is given, x exists in A.
- After processing each query, A is not empty, and its elements are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
Here, \mathrm{Query}_i represents the i-th query and is given in one of the following formats:
1 x y
2 x
Output
Let A=(A_1,\ldots,A_K) be the sequence after processing all the queries. Print A_1,\ldots,A_K in this order, separated by spaces.
Sample Input 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
Sample Output 1
4 5 1 3
The queries are processed as follows:
- Initially, A=(2,1,4,3).
- The first query removes 1, making A=(2,4,3).
- The second query inserts 5 immediately after 4, making A=(2,4,5,3).
- The third query removes 2, making A=(4,5,3).
- The fourth query inserts 1 immediately after 5, making A=(4,5,1,3).
Sample Input 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
Sample Output 2
5 1 7 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
N 人の人がおり、人にはそれぞれ 1, 2, \ldots, N の番号が付けられています。
N 人が競争を行い、順位が付きました。この順位に対して以下の情報が与えられています。
- それぞれの人に対して付けられた順位は相異なる
- 各 1 \leq i \leq M について人 A_i の順位を x、人 B_i の順位を y とすると、x - y = C_i である
ただし、この問題では与えられた情報に矛盾しないような順位付けが 1 つ以上存在するような入力のみが与えられます。
N 個のクエリの答えを求めてください。i 番目のクエリの答えは以下により定まる整数です。
- 人 i の順位が一意に定まるならば、その値を答えとする。そうでない場合、答えは -1 である。
制約
- 2 \leq N \leq 16
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i, B_i \leq N
- 1 \leq C_i \leq N - 1
- (A_i, B_i) \neq (A_j, B_j) (i \neq j)
- 与えられた情報に矛盾しない順位付けが 1 つ以上存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
出力
1, 2, \ldots ,N 番目のクエリに対する答えをこの順に空白区切りで出力せよ。
入力例 1
5 2 2 3 3 5 4 3
出力例 1
3 -1 -1 -1 -1
人 i の順位を X_i とおくと、(X_1, X_2, X_3, X_4, X_5) は (3, 4, 1, 2, 5), (3, 5, 2, 1, 4) のいずれかです。
したがって、1 番目のクエリに対する答えは 3、2, 3, 4, 5 番目のクエリに対する答えは -1 となります。
入力例 2
3 0
出力例 2
-1 -1 -1
入力例 3
8 5 6 7 3 8 1 7 4 5 1 7 2 1 6 2 4
出力例 3
1 -1 -1 -1 -1 -1 -1 8
Score: 525 points
Problem Statement
There are N people, numbered 1 to N.
A competition was held among these N people, and they were ranked accordingly. The following information is given about their ranks:
- Each person has a unique rank.
- For each 1 \leq i \leq M, if person A_i is ranked x-th and person B_i is ranked y-th, then x - y = C_i.
The given input guarantees that there is at least one possible ranking that does not contradict the given information.
Answer N queries. The answer to the i-th query is an integer determined as follows:
- If the rank of person i can be uniquely determined, return that rank. Otherwise, return -1.
Constraints
- 2 \leq N \leq 16
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i, B_i \leq N
- 1 \leq C_i \leq N - 1
- (A_i, B_i) \neq (A_j, B_j) (i \neq j)
- There is at least one possible ranking that does not contradict the given information.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
Output
Print the answers to the 1-st, 2-nd, \ldots, N-th queries in this order, separated by spaces.
Sample Input 1
5 2 2 3 3 5 4 3
Sample Output 1
3 -1 -1 -1 -1
Let X_i be the rank of person i. Then, (X_1, X_2, X_3, X_4, X_5) could be (3, 4, 1, 2, 5) or (3, 5, 2, 1, 4).
Therefore, the answer to the 1-st query is 3, and the answers to the 2-nd, 3-rd, 4-th, and 5-th queries are -1.
Sample Input 2
3 0
Sample Output 2
-1 -1 -1
Sample Input 3
8 5 6 7 3 8 1 7 4 5 1 7 2 1 6 2 4
Sample Output 3
1 -1 -1 -1 -1 -1 -1 8