Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
この問題は F 問題 (Operate K) の部分問題であり、 K=1 です。
F 問題に正解するコードをこの問題に提出することで、この問題に正解できます。
文字列 S に対して以下の操作を 0 回以上 K 回以下行って、文字列 T と一致させられるか判定してください。
- 次の 3 種類の操作のうちひとつを選択し、実行する。
- S 中の (先頭や末尾を含む) 任意の位置に、任意の文字を 1 つ挿入する。
- S 中の文字を 1 つ選び、削除する。
- S 中の文字を 1 つ選び、別の 1 つの文字に変更する。
制約
- S,T は英小文字からなる長さ 1 以上 500000 以下の文字列
- \color{red}{K=1}
入力
入力は以下の形式で標準入力から与えられる。
K S T
出力
K 回以下の操作で S を T に一致させられる時 Yes 、そうでない時 No と出力せよ。
入力例 1
1 abc agc
出力例 1
Yes
abc の 2 文字目の b を g に置き換えることで、 abc を 1 回の操作で agc に変換できます。
入力例 2
1 abc awtf
出力例 2
No
1 回の操作では abc を awtf に変換できません。
入力例 3
1 abc ac
出力例 3
Yes
abc の 2 文字目の b を削除することで、 abc を 1 回の操作で ac に変換できます。
入力例 4
1 back black
出力例 4
Yes
back の 1 文字目と 2 文字目の間に l を挿入することで、 back を 1 回の操作で black に変換できます。
入力例 5
1 same same
出力例 5
Yes
初めから S=T である場合もあります。
入力例 6
1 leap read
出力例 6
No
Score : 350 points
Problem Statement
This problem is a sub-problem of Problem F (Operate K), with K=1.
You can solve this problem by submitting a correct solution for Problem F to this problem.
Determine whether it is possible to perform the following operation on string S between 0 and K times, inclusive, to make it identical to string T.
- Choose one of the following three operations and execute it.
- Insert any one character at any position in S (possibly the beginning or end).
- Delete one character from S.
- Choose one character in S and replace it with another character.
Constraints
- Each of S and T is a string of length between 1 and 500000, inclusive, consisting of lowercase English letters.
- \color{red}{K=1}
Input
The input is given from Standard Input in the following format:
K S T
Output
If S can be made identical to T with at most K operations, print Yes; otherwise, print No.
Sample Input 1
1 abc agc
Sample Output 1
Yes
Replacing the second character b of abc with g converts abc to agc in one operation.
Sample Input 2
1 abc awtf
Sample Output 2
No
abc cannot be converted to awtf in one operation.
Sample Input 3
1 abc ac
Sample Output 3
Yes
Deleting the second character b of abc converts abc to ac in one operation.
Sample Input 4
1 back black
Sample Output 4
Yes
Inserting l between the first and second characters of back converts back to black in one operation.
Sample Input 5
1 same same
Sample Output 5
Yes
It is also possible that S = T from the beginning.
Sample Input 6
1 leap read
Sample Output 6
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
文字列 S の各文字を並べ替えて作ることが可能な文字列を辞書順にすべて列挙したとき、前から K 番目にくる文字列を求めてください。
「各文字を並べ替えて作ることが可能な文字列」とは?
「文字列 A が文字列 B の各文字を並べ替えて作ることが可能な文字列である」とは、任意の文字が文字列 A と文字列 B に同数含まれるということを指します。制約
- 1 \le |S| \le 8
- S は英小文字のみからなる
- S の各文字を並べ替えてできる文字列は K 種類以上存在する
入力
入力は以下の形式で標準入力から与えられる。
S K
出力
答えを出力せよ。
入力例 1
aab 2
出力例 1
aba
文字列 aab の各文字を並べ替えて作ることが可能な文字列は \{ aab, aba, baa \} の 3 つですが、このうち辞書順で前から 2 番目にくるものは aba です。
入力例 2
baba 4
出力例 2
baab
入力例 3
ydxwacbz 40320
出力例 3
zyxwdcba
Score : 300 points
Problem Statement
Find the K-th lexicographically smallest string among the strings that are permutations of a string S.
What is a permutation of a string?
A string A is said to be a permutation of a string B when any character occurs the same number of times in A and B.Constraints
- 1 \le |S| \le 8
- S consists of lowercase English letters.
- There are at least K distinct strings that are permutations of S.
Input
Input is given from Standard Input in the following format:
S K
Output
Print the answer.
Sample Input 1
aab 2
Sample Output 1
aba
There are three permutations of a string aab: \{ aab, aba, baa \}. The 2-nd lexicographically smallest of them is aba.
Sample Input 2
baba 4
Sample Output 2
baab
Sample Input 3
ydxwacbz 40320
Sample Output 3
zyxwdcba
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 人のスポーツ選手がいます。
N 人の選手たちには互いに相性の悪い選手のペアが M 組あり、相性の悪い組のうち i\ (1\leq i\leq M) 組目は A _ i 番目の選手と B _ i 番目の選手です。
あなたは、選手を T チームに分けます。 どの選手もちょうど一つのチームに属さなければならず、どのチームにも少なくとも一人の選手が属さなければなりません。 さらに、どの i=1,2,\ldots,M についても、 A _ i 番目の選手と B _ i 番目の選手が同じチームに属していてはいけません。
この条件を満たすチーム分けの方法は何通りあるか求めてください。 ただし、チーム分けの方法が異なるとは、ある二人が存在して、彼らが一方のチーム分けでは同じチームに所属し、もう一方では異なるチームに所属することをいいます。
制約
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
出力
答えを 1 行で出力せよ。
入力例 1
5 2 2 1 3 3 4
出力例 1
4
次の 4 通りのチーム分けが条件を満たします。

他に条件を満たすチーム分けは存在しないので、4 を出力してください。
入力例 2
5 1 2 1 3 3 4
出力例 2
0
条件を満たすチーム分けがひとつも存在しないこともあります。
入力例 3
6 4 0
出力例 3
65
相性の悪いペアがひとつも存在しないこともあります。
入力例 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
出力例 4
8001
Score : 400 points
Problem Statement
There are N sports players.
Among them, there are M incompatible pairs. The i-th incompatible pair (1\leq i\leq M) is the A_i-th and B_i-th players.
You will divide the players into T teams. Every player must belong to exactly one team, and every team must have one or more players. Additionally, for each i=1,2,\ldots,M, the A_i-th and B_i-th players must not belong to the same team.
Find the number of ways to satisfy these conditions. Here, two divisions are considered different when there are two players who belong to the same team in one division and different teams in the other.
Constraints
- 1\leq T\leq N\leq10
- 0\leq M\leq\dfrac{N(N-1)}2
- 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
- (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T M A _ 1 B _ 1 A _ 2 B _ 2 \vdots A _ M B _ M
Output
Print the answer in a single line.
Sample Input 1
5 2 2 1 3 3 4
Sample Output 1
4
The following four divisions satisfy the conditions.

No other division satisfies them, so print 4.
Sample Input 2
5 1 2 1 3 3 4
Sample Output 2
0
There may be no division that satisfies the conditions.
Sample Input 3
6 4 0
Sample Output 3
65
There may be no incompatible pair.
Sample Input 4
10 6 8 5 9 1 4 3 8 1 6 4 10 5 7 5 6 3 7
Sample Output 4
8001
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
正整数 n の桁和を、n を 10 進法で表したときの各桁の和と定義します。例えば 2025 の桁和は 2 + 0 + 2 + 5 = 9 です。
正整数 n が n の桁和で割り切れる時、n を 良い整数 と呼びます。例えば 2025 はその桁和である 9 で割り切れるので良い整数です。
正整数の組 (a, a+1) であって a と a+1 が共に良い整数であるものを 双子の良い整数 と呼びます。例えば (2024, 2025) は双子の良い整数です。
正整数 N が与えられます。N \leq a かつ a + 1 \leq 2N であるような双子の良い整数 (a, a + 1) を発見してください。そのような (a, a + 1) が存在しない場合はそのことを報告してください。
制約
- N は 1 以上 10^{100000} 未満の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
問題文の条件を満たす (a, a+1) が存在する場合は a を、存在しない場合は -1 を出力せよ。a は leading-zeros を省略した表現で出力する必要がある点に注意せよ。
条件を満たす (a, a+1) が複数存在する場合はどれを出力してもよい。
入力例 1
5
出力例 1
8
(8, 9) は問題文の条件を満たす双子の良い整数です。他にも (5, 6), (6, 7), (7, 8), (9, 10) が条件を満たします。
入力例 2
21
出力例 2
-1
問題文の条件を満たす双子の良い整数は存在しません。
入力例 3
1234
出力例 3
2024
(2024, 2025) は問題文の条件を満たす双子の良い整数です。
入力例 4
1234567890123456789012345678901234567890
出力例 4
1548651852734633803438094164372911259190
Score : 500 points
Problem Statement
The digit sum of a positive integer n is defined as the sum of its digits when n is written in decimal. For example, the digit sum of 2025 is 2 + 0 + 2 + 5 = 9.
A positive integer n is called a good integer if it is divisible by its digit sum. For example, 2025 is a good integer because it is divisible by its digit sum of 9.
A pair of positive integers (a, a+1) is called twin good integers if both a and a+1 are good integers. For example, (2024, 2025) is twin good integers.
You are given a positive integer N. Find a pair of twin good integers (a, a + 1) such that N \leq a and a + 1 \leq 2N. If no such pair exists, report that fact.
Constraints
- N is an integer at least 1 and less than 10^{100000}.
Input
The input is given from Standard Input in the following format:
N
Output
If there exists such a pair (a, a+1), output a. Otherwise, output -1. Do not print leading zeros.
If there are multiple such pairs, you may print any.
Sample Input 1
5
Sample Output 1
8
(8, 9) is a valid pair of twin good integers satisfying the conditions. Other examples include (5, 6), (6, 7), (7, 8), (9, 10).
Sample Input 2
21
Sample Output 2
-1
No pair of twin good integers satisfies the conditions.
Sample Input 3
1234
Sample Output 3
2024
(2024, 2025) is a valid pair of twin good integers.
Sample Input 4
1234567890123456789012345678901234567890
Sample Output 4
1548651852734633803438094164372911259190
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
長さ N の非負整数列 A = (A_1, \dots, A_N) が与えられます。
k = 1, \dots, N について、次の問題を解いてください。
- A の連続部分列のうち長さが k のものは N-k+1 個ある。それぞれの連続部分列について最大値を求めたとき、それらの合計を求めよ。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq A_i \leq 10^7 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
N 行出力せよ。i 行目 (1 \leq i \leq N) には、k = i に対する答えを出力せよ。
入力例 1
4 5 3 4 2
出力例 1
14 13 9 5
k = 1 の場合、長さ k=1 の連続部分列は 4 個あり、それぞれについて
- (5) の最大値は 5
- (3) の最大値は 3
- (4) の最大値は 4
- (2) の最大値は 2
となり、これらの合計は 5+3+4+2 = 14 です。
k = 2 の場合、長さ k=2 の連続部分列は 3 個あります。それぞれについて
- (5,3) の最大値は 5
- (3,4) の最大値は 4
- (4,2) の最大値は 4
となり、これらの合計は 5+4+4 = 13 です。
k = 3 の場合、長さ k=3 の連続部分列は 2 個あります。それぞれについて
- (5,3,4) の最大値は 5
- (3,4,2) の最大値は 4
となり、これらの合計は 5+4 = 9 です。
k = 4 の場合、長さ k=4 の連続部分列は 1 個あります。それぞれについて
- (5,3,4,2) の最大値は 5
となり、これらの合計は 5 です。
入力例 2
8 2 0 2 5 0 5 2 4
出力例 2
20 28 27 25 20 15 10 5
入力例 3
11 9203973 9141294 9444773 9292472 5507634 9599162 497764 430010 4152216 3574307 430010
出力例 3
61273615 68960818 69588453 65590626 61592799 57594972 47995810 38396648 28797486 19198324 9599162
Score : 550 points
Problem Statement
You are given a sequence of non-negative integers A = (A_1,\dots,A_N) of length N.
For each k = 1,\dots,N, solve the following problem:
- A has N-k+1 (contiguous) subarrays of length k. Take the maximum of each of them, and output the sum of these maxima.
Constraints
- 1 \le N \le 2 \times 10^{5}
- 0 \le A_i \le 10^{7} (1 \le i \le N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Output N lines. The i-th line (1 \le i \le N) should contain the answer for k = i.
Sample Input 1
4 5 3 4 2
Sample Output 1
14 13 9 5
For k = 1, there are four subarrays of length k=1:
- (5), whose maximum is 5;
- (3), whose maximum is 3;
- (4), whose maximum is 4;
- (2), whose maximum is 2.
The sum is 5 + 3 + 4 + 2 = 14.
For k = 2, there are three subarrays of length k=2:
- (5,3), whose maximum is 5;
- (3,4), whose maximum is 4;
- (4,2), whose maximum is 4.
The sum is 5 + 4 + 4 = 13.
For k = 3, there are two subarrays of length k=3:
- (5,3,4), whose maximum is 5;
- (3,4,2), whose maximum is 4.
The sum is 5 + 4 = 9.
For k = 4, there is one subarray of length k=4:
- (5,3,4,2), whose maximum is 5.
The sum is 5.
Sample Input 2
8 2 0 2 5 0 5 2 4
Sample Output 2
20 28 27 25 20 15 10 5
Sample Input 3
11 9203973 9141294 9444773 9292472 5507634 9599162 497764 430010 4152216 3574307 430010
Sample Output 3
61273615 68960818 69588453 65590626 61592799 57594972 47995810 38396648 28797486 19198324 9599162