実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
髙橋君はサッカーの試合で N 回ペナルティキックを蹴ります。
髙橋君は i 回目のペナルティキックでは、i が 3 の倍数の場合は失敗しそれ以外の場合は成功します。
髙橋君がペナルティキックを蹴ったときの結果を出力してください。
制約
- 1 \leq N \leq 100
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
髙橋君のペナルティキックの結果を表す長さ N の文字列を出力せよ。結果を表す文字列の i (1 \leq i \leq N) 文字目は髙橋君が i 回目のペナルティキックで成功した場合は o 、失敗した場合は x とする。
入力例 1
7
出力例 1
ooxooxo
髙橋君は 3 回目と 6 回目のペナルティキックに失敗するので、3 文字目と 6 文字目が x となります。
入力例 2
9
出力例 2
ooxooxoox
Score: 100 points
Problem Statement
Takahashi will have N penalty kicks in a soccer match.
For the i-th penalty kick, he will fail if i is a multiple of 3, and succeed otherwise.
Print the results of his penalty kicks.
Constraints
- 1 \leq N \leq 100
- All inputs are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Print a string of length N representing the results of Takahashi's penalty kicks. The i-th character (1 \leq i \leq N) should be o if Takahashi succeeds in the i-th penalty kick, and x if he fails.
Sample Input 1
7
Sample Output 1
ooxooxo
Takahashi fails the third and sixth penalty kicks, so the third and sixth characters will be x.
Sample Input 2
9
Sample Output 2
ooxooxoox
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ 3 の英大文字からなる文字列 S が与えられます。
S の各文字を並び替えることで S を文字列 ABC と一致させることができるか判定してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えることで文字列 ABC と一致させることができるなら Yes を、そうでないなら No を出力せよ。
入力例 1
BAC
出力例 1
Yes
S の 1 文字目と S の 2 文字目を入れ替えることで ABC と一致させることができます。
入力例 2
AAC
出力例 2
No
どのように並び替えても S を ABC と一致させることはできません。
入力例 3
ABC
出力例 3
Yes
入力例 4
ARC
出力例 4
No
Score : 100 points
Problem Statement
You are given a string S of length 3 consisting of uppercase English letters.
Determine whether it is possible to rearrange the characters in S to make it match the string ABC.
Constraints
- S is a string of length 3 consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if it is possible to rearrange the characters in S to make it match the string ABC, and No otherwise.
Sample Input 1
BAC
Sample Output 1
Yes
You can make S match ABC by swapping the first and second characters of S.
Sample Input 2
AAC
Sample Output 2
No
You cannot make S match ABC no matter how you rearrange the characters.
Sample Input 3
ABC
Sample Output 3
Yes
Sample Input 4
ARC
Sample Output 4
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字のみからなる N 個の文字列 S_1,S_2,\ldots,S_N が与えられます。
1 以上 N 以下の 相異なる 整数 i,j であって、S_i と S_j をこの順に連結した文字列が回文となるようなものが存在するか判定してください。
ただし、長さ M の文字列 T が回文であるとは、任意の 1\leq i\leq M について、T の i 文字目と (M+1-i) 文字目が一致していることをいいます。
制約
- 2\leq N\leq 100
- 1\leq \lvert S_i\rvert \leq 50
- N は整数
- S_i は英小文字のみからなる文字列
- S_i はすべて異なる。
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文の条件をみたす i,j が存在するならば Yes を、そうでないならば No を出力せよ。
入力例 1
5 ab ccef da a fe
出力例 1
Yes
(i,j)=(1,4) とすると、S_1=ab と S_4=a をこの順に連結した文字列は aba となり、
これは回文であるため条件をみたしています。
よって、Yes を出力します。
また、(i,j)=(5,2) としても、S_5=fe と S_2=ccef をこの順に連結した文字列は feccef となり、やはり条件をみたしています。
入力例 2
3 a b aba
出力例 2
No
S_1, S_2, S_3 のうち、どの相異なる 2 つの文字列を繋げても回文となりません。
よって、No を出力します。
問題文における i,j は相異なる必要があることに注意してください。
入力例 3
2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
出力例 3
Yes
Score : 200 points
Problem Statement
You are given N strings S_1,S_2,\ldots,S_N consisting of lowercase English letters.
Determine if there are distinct integers i and j between 1 and N, inclusive, such that the concatenation of S_i and S_j in this order is a palindrome.
A string T of length M is a palindrome if and only if the i-th character and the (M+1-i)-th character of T are the same for every 1\leq i\leq M.
Constraints
- 2\leq N\leq 100
- 1\leq \lvert S_i\rvert \leq 50
- N is an integer.
- S_i is a string consisting of lowercase English letters.
- All S_i are distinct.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If there are i and j that satisfy the condition in the problem statement, print Yes; otherwise, print No.
Sample Input 1
5 ab ccef da a fe
Sample Output 1
Yes
If we take (i,j)=(1,4), the concatenation of S_1=ab and S_4=a in this order is aba, which is a palindrome, satisfying the condition.
Thus, print Yes.
Here, we can also take (i,j)=(5,2), for which the concatenation of S_5=fe and S_2=ccef in this order is feccef, satisfying the condition.
Sample Input 2
3 a b aba
Sample Output 2
No
No two distinct strings among S_1, S_2, and S_3 form a palindrome when concatenated.
Thus, print No.
Note that the i and j in the statement must be distinct.
Sample Input 3
2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君には、穴 1,2,\dots,N に 1 本ずつ、全部で N 本の歯が生えています。
歯医者の青木君は、これらの歯と穴に対して、 Q 回の治療を行います。
i 回目の治療では、穴 T_i を治療します。治療内容は次の通りです。
- 穴 T_i に歯が生えている場合、穴 T_i から歯を抜く。
- そうでない ( 穴 T_i に歯が生えていない) 場合、穴 T_i に歯を生やす。
全ての治療が終わった後、高橋君に生えている歯の本数は何本ですか?
制約
- 入力は全て整数
- 1 \le N,Q \le 1000
- 1 \le T_i \le N
入力
入力は以下の形式で標準入力から与えられる。
N Q T_1 T_2 \dots T_Q
出力
答えを整数として出力せよ。
入力例 1
30 6 2 9 18 27 18 9
出力例 1
28
高橋君には最初 30 本の歯が生えており、青木君は 6 回の治療を行います。
- 1 回目の治療では穴 2 を治療します。 穴 2 に歯が生えているため、歯を抜きます。
- 2 回目の治療では穴 9 を治療します。 穴 9 に歯が生えているため、歯を抜きます。
- 3 回目の治療では穴 18 を治療します。 穴 18 に歯が生えているため、歯を抜きます。
- 4 回目の治療では穴 27 を治療します。 穴 27 に歯が生えているため、歯を抜きます。
- 5 回目の治療では穴 18 を治療します。 穴 18 に歯が生えていないため、歯を生やします。
- 6 回目の治療では穴 9 を治療します。 穴 9 に歯が生えていないため、歯を生やします。
最終的な歯の本数は 28 本です。
入力例 2
1 7 1 1 1 1 1 1 1
出力例 2
0
入力例 3
9 20 9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8
出力例 3
5
Score: 200 points
Problem Statement
Takahashi has N teeth, one in each of the holes numbered 1, 2, \dots, N.
Dentist Aoki will perform Q treatments on these teeth and holes.
In the i-th treatment, hole T_i is treated as follows:
- If there is a tooth in hole T_i, remove the tooth from hole T_i.
- If there is no tooth in hole T_i (i.e., the hole is empty), grow a tooth in hole T_i.
After all treatments are completed, how many teeth does Takahashi have?
Constraints
- All input values are integers.
- 1 \le N, Q \le 1000
- 1 \le T_i \le N
Input
The input is given from Standard Input in the following format:
N Q T_1 T_2 \dots T_Q
Output
Print the number of teeth as an integer.
Sample Input 1
30 6 2 9 18 27 18 9
Sample Output 1
28
Initially, Takahashi has 30 teeth, and Aoki performs six treatments.
- In the first treatment, hole 2 is treated. There is a tooth in hole 2, so it is removed.
- In the second treatment, hole 9 is treated. There is a tooth in hole 9, so it is removed.
- In the third treatment, hole 18 is treated. There is a tooth in hole 18, so it is removed.
- In the fourth treatment, hole 27 is treated. There is a tooth in hole 27, so it is removed.
- In the fifth treatment, hole 18 is treated. There is no tooth in hole 18, so a tooth is grown.
- In the sixth treatment, hole 9 is treated. There is no tooth in hole 9, so a tooth is grown.
The final count of teeth is 28.
Sample Input 2
1 7 1 1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
9 20 9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8
Sample Output 3
5
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
列 S_n を次のように定義します。
- S_1 は 1 つの 1 からなる長さ 1 の列である。
- S_n (n は 2 以上の整数) は S_{n-1}, n, S_{n-1} をこの順につなげた列である。
たとえば S_2,S_3 は次のような列です。
- S_2 は S_1, 2, S_1 をこの順につなげた列なので 1,2,1 である。
- S_3 は S_2, 3, S_2 をこの順につなげた列なので 1,2,1,3,1,2,1 である。
N が与えられるので、列 S_N をすべて出力してください。
制約
- N は整数
- 1 \leq N \leq 16
入力
入力は以下の形式で標準入力から与えられる。
N
出力
S_N を空白区切りで出力せよ。
入力例 1
2
出力例 1
1 2 1
問題文の説明にある通り、S_2 は 1,2,1 となります。
入力例 2
1
出力例 2
1
入力例 3
4
出力例 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
S_4 は S_3,4,S_3 をこの順につなげた列です。
Score : 300 points
Problem Statement
We define sequences S_n as follows.
- S_1 is a sequence of length 1 containing a single 1.
- S_n (n is an integer greater than or equal to 2) is a sequence obtained by concatenating S_{n-1}, n, S_{n-1} in this order.
For example, S_2 and S_3 is defined as follows.
- S_2 is a concatenation of S_1, 2, and S_1, in this order, so it is 1,2,1.
- S_3 is a concatenation of S_2, 3, and S_2, in this order, so it is 1,2,1,3,1,2,1.
Given N, print the entire sequence S_N.
Constraints
- N is an integer.
- 1 \leq N \leq 16
Input
Input is given from Standard Input in the following format:
N
Output
Print S_N, with spaces in between.
Sample Input 1
2
Sample Output 1
1 2 1
As described in the Problem Statement, S_2 is 1,2,1.
Sample Input 2
1
Sample Output 2
1
Sample Input 3
4
Sample Output 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
- S_4 is a concatenation of S_3, 4, and S_3, in this order.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
空の整数列 A=() があります。クエリが Q 個与えられるので、与えられた順に処理してください。クエリは以下の 2 種類です。
- タイプ 1 :
1 c xの形式で与えられる。A の末尾に x を c 個追加する。 - タイプ 2 :
2 kの形式で与えられる。A の先頭 k 要素を削除し、削除した k 個の整数の総和を出力する。このとき、k はその時点での A の長さ以下であることが保証される。
制約
- 1 \leq Q \leq 2 \times 10^{5}
- タイプ 1 のクエリにおいて、 1 \leq c \leq 10^{9}
- タイプ 1 のクエリにおいて、 1 \leq x \leq 10^{9}
- タイプ 2 のクエリにおいて、その時点での A の長さを n として、 1 \leq k \leq \min(10^{9},n)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
ただし、 \text{query}_i は i 個目のクエリを表し、以下のいずれかの形式である。
1 c x
2 k
出力
タイプ 2 のクエリの個数を q として、q 行出力せよ。i 行目には、i 個目のタイプ 2 のクエリに対する答えを出力せよ。
入力例 1
5 1 2 3 1 4 5 2 3 1 6 2 2 5
出力例 1
11 19
- 1 個目のクエリ: A の末尾に 3 を 2 個追加する。このとき、A=(3,3) となる。
- 2 個目のクエリ: A の末尾に 5 を 4 個追加する。このとき、A=(3,3,5,5,5,5) となる。
- 3 個目のクエリ: A の先頭 3 要素を削除する。このとき、削除した 3 個の整数の総和は 3+3+5=11 となるため 11 と出力する。削除後、A=(5,5,5) となる。
- 4 個目のクエリ: A の末尾に 2 を 6 個追加する。このとき、A=(5,5,5,2,2,2,2,2,2) となる。
- 5 個目のクエリ: A の先頭 5 要素を削除する。このとき、削除した 5 個の整数の総和は 5+5+5+2+2=19 となるため 19 と出力する。削除後、A=(2,2,2,2) となる。
入力例 2
10 1 75 22 1 81 72 1 2 97 1 84 82 1 2 32 1 39 57 2 45 1 40 16 2 32 2 42
出力例 2
990 804 3024
入力例 3
10 1 160449218 954291757 2 17217760 1 353195922 501899080 1 350034067 910748511 1 824284691 470338674 2 180999835 1 131381221 677959980 1 346948152 208032501 1 893229302 506147731 2 298309896
出力例 3
16430766442004320 155640513381884866 149721462357295680
Score : 300 points
Problem Statement
There is an empty integer sequence A=(). You are given Q queries, and you need to process them in the given order. There are two types of queries:
- Type 1: Given in the format
1 c x. Add c copies of x to the end of A. - Type 2: Given in the format
2 k. Remove the first k elements from A and output the sum of the removed k integers. It is guaranteed that k is at most the length of A at that time.
Constraints
- 1 \leq Q \leq 2 \times 10^{5}
- In type 1 queries, 1 \leq c \leq 10^{9}.
- In type 1 queries, 1 \leq x \leq 10^{9}.
- In type 2 queries, letting n be the length of A at that time, 1 \leq k \leq \min(10^{9},n).
- 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
where \text{query}_i represents the i-th query and is in one of the following formats:
1 c x
2 k
Output
Let q be the number of type 2 queries. Output q lines. The i-th line should contain the answer to the i-th type 2 query.
Sample Input 1
5 1 2 3 1 4 5 2 3 1 6 2 2 5
Sample Output 1
11 19
- 1st query: Add 2 copies of 3 to the end of A. Then, A=(3,3).
- 2nd query: Add 4 copies of 5 to the end of A. Then, A=(3,3,5,5,5,5).
- 3rd query: Remove the first 3 elements from A. Then, the sum of the removed 3 integers is 3+3+5=11, so output 11. After removal, A=(5,5,5).
- 4th query: Add 6 copies of 2 to the end of A. Then, A=(5,5,5,2,2,2,2,2,2).
- 5th query: Remove the first 5 elements from A. Then, the sum of the removed 5 integers is 5+5+5+2+2=19, so output 19. After removal, A=(2,2,2,2).
Sample Input 2
10 1 75 22 1 81 72 1 2 97 1 84 82 1 2 32 1 39 57 2 45 1 40 16 2 32 2 42
Sample Output 2
990 804 3024
Sample Input 3
10 1 160449218 954291757 2 17217760 1 353195922 501899080 1 350034067 910748511 1 824284691 470338674 2 180999835 1 131381221 677959980 1 346948152 208032501 1 893229302 506147731 2 298309896
Sample Output 3
16430766442004320 155640513381884866 149721462357295680
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 以下の正整数のうち、正の約数をちょうど 9 個持つものの個数を求めてください。
制約
- 1\leq N\leq 4\times 10^{12}
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
200
出力例 1
3
条件を満たす正整数は 36,100,196 の 3 個です。
入力例 2
4000000000000
出力例 2
407073
Score : 400 points
Problem Statement
Find the number of positive integers not greater than N that have exactly 9 positive divisors.
Constraints
- 1 \leq N \leq 4 \times 10^{12}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
200
Sample Output 1
3
Three positive integers 36,100,196 satisfy the condition.
Sample Input 2
4000000000000
Sample Output 2
407073
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
正の整数 N,K が与えられます。
N 以下の正の整数 x であって、次の条件をみたすものの 総和 を 998244353 で割った余りを求めてください。
- x の popcount の値はちょうど K である。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
popcount とは
正整数 y に対して、y の popcount の値 \mathrm{popcount}(y) は、y を二進数表記したとき 1 となっている桁の個数を表します。 例えば、\mathrm{popcount}(5)=2, \mathrm{popcount}(16)=1, \mathrm{popcount}(25)=3 です。制約
- 1\leq T\leq 100
- 1\leq N < 2^{60}
- 1\leq K \leq 60
- T,N,K は整数
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i は i 番目のテストケースを表す。 各テストケースは以下の形式で与えられる。
N K
出力
T 行出力せよ。i 行目 (1\leq i\leq T) には i 番目のテストケースに対する答えを出力せよ。
入力例 1
2 20 2 1234567890 17
出力例 1
100 382730918
1 番目のテストケースについて、20 以下の正の整数のうち、popcount の値が 2 であるものは 3,5,6,9,10,12,17,18,20 の 9 つであり、その総和は 100 となります。
100 を 998244353 で割った余りは 100 であるため、1 行目には 100 を出力します。
998244353 で割った余りを出力する必要があることに注意してください。
Score : 450 points
Problem Statement
You are given positive integers N and K.
Find the sum, modulo 998244353, of all positive integers x that do not exceed N and satisfy the following condition:
- the popcount of x is exactly K.
You are given T test cases; solve each of them.
What is popcount?
For a positive integer y, \mathrm{popcount}(y) denotes the number of 1 bits in the binary representation of y. For example, \mathrm{popcount}(5)=2, \mathrm{popcount}(16)=1, \mathrm{popcount}(25)=3.Constraints
- 1 \leq T \leq 100
- 1 \leq N < 2^{60}
- 1 \leq K \leq 60
- T, N, and K are integers.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i denotes the i-th test case. Each test case is given in the following format:
N K
Output
Output T lines. The i-th line (1 \leq i \leq T) should contain the answer for the i-th test case.
Sample Input 1
2 20 2 1234567890 17
Sample Output 1
100 382730918
For the first test case, there are nine positive integers not exceeding 20 whose popcount is 2: 3, 5, 6, 9, 10, 12, 17, 18, 20. Their sum is 100.
The remainder when 100 is divided by 998244353 is 100, so output 100 on the first line.
Remember to output the sum modulo 998244353.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
高橋君と青木君は、これから N 日間アルバイトをします。
高橋君のシフト表は文字列 S により与えられ、S の i 文字目が # のとき i 日目に出勤、. のとき i 日目に欠勤します。
これをもとに、青木君は以下のようにシフト表を作りました。
- まず、N でない N の正の約数 M をとる。
- 次に、1 日目から M 日目までの勤怠を決める。
- 最後に、i = 1, 2, \ldots, N - M の順に M + i 日目の勤怠が i 日目の勤怠と一致するように M + i 日目の勤怠を決める。
ここで、M の値が異なる場合でも最終的にできたシフトが同じものとなることがあることに注意してください。
N 日すべてについて高橋君と青木君の少なくとも一方が出勤することになったとき、青木君のシフト表として考えられるものの個数を 998244353 で割った余りを求めてください。
制約
- N は 2 以上 10^5 以下の整数
- S は 長さ N の
#、.からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
6 ##.#.#
出力例 1
3
高橋君は 1 \cdot 2 \cdot 4 \cdot 6 日目に出勤します。
青木君のシフト表を表す文字列を T とし、青木君は T の i 文字目が # のとき i 日目に出勤、. のとき i 日目に欠勤するとします。
T としてあり得るものは ###### \cdot #.#.#. \cdot .##.## の 3 つです。
1 つめのシフト表は M を 1 または 2 または 3、2 つめのシフト表は M = 2、3 つめのシフト表は M = 3 とすることにより実現できます。
入力例 2
7 ...####
出力例 2
1
入力例 3
12 ####.####.##
出力例 3
19
Score : 525 points
Problem Statement
Takahashi and Aoki will work part-time for the next N days.
Takahashi's shift schedule is given by the string S, where the i-th character of S is # if he works on the i-th day, and . if he is absent on the i-th day.
Based on this, Aoki created his shift schedule as follows.
- First, take a positive divisor M of N that is not equal to N.
- Next, decide the attendance for the first M days.
- Finally, for i = 1, 2, \ldots, N - M in this order, decide the attendance for the (M + i)-th day so that it matches the attendance for the i-th day.
Note that different values of M may lead to the same final shift schedule.
Find the number of possible shift schedules for Aoki such that at least one of Takahashi and Aoki works on each of the N days, modulo 998244353.
Constraints
- N is an integer between 2 and 10^5, inclusive.
- S is a string of length N consisting of
#and..
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
6 ##.#.#
Sample Output 1
3
Takahashi works on days 1, 2, 4, and 6.
Let T be the string representing Aoki's shift schedule, where the i-th character of T is # if he works on the i-th day, and . if he is absent on the i-th day.
There are three possible strings for T: ######, #.#.#., and .##.##.
The first shift schedule can be realized by choosing M = 1 or 2 or 3, the second by choosing M = 2, and the third by choosing M = 3.
Sample Input 2
7 ...####
Sample Output 2
1
Sample Input 3
12 ####.####.##
Sample Output 3
19