実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。
つまり、 ID は以下の順番で付けられています。
- 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
- ...
このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。
制約
- S は AtCoder Big Contest に含まれる問題の ID として正しい
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
AB
出力例 1
28
ID が AB である問題は、 AtCoder Big Contest の 28 問目です。
入力例 2
C
出力例 2
3
ID が C である問題は、 AtCoder Big Contest の 3 問目です。
入力例 3
BRUTMHYHIIZP
出力例 3
10000000000000000
ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。
Score : 300 points
Problem Statement
In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...
In other words, the IDs are given in the following order:
- the strings of length 1 consisting of uppercase English letters, in lexicographical order;
- the strings of length 2 consisting of uppercase English letters, in lexicographical order;
- the strings of length 3 consisting of uppercase English letters, in lexicographical order;
- ...
Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)
Constraints
- S is a valid ID of a problem given in AtCoder Big Contest.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
AB
Sample Output 1
28
The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.
Sample Input 2
C
Sample Output 2
3
The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.
Sample Input 3
BRUTMHYHIIZP
Sample Output 3
10000000000000000
The problem whose ID is BRUTMHYHIIZP is the 
10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字のみからなる長さ N の文字列 S = S_1S_2\ldots S_N が与えられます。
また、S に関する Q 個の質問が与えられます。 i = 1, 2, \ldots, Q について、i 番目の質問は 2 つの整数 l_i, r_i で表される下記の質問です。
S の l_i 文字目から r_i 文字目までからなる部分文字列 S_{l_i}S_{l_i+1}\ldots S_{r_i} において、 同じ英小文字が 2 つ隣りあう箇所は何個ありますか? すなわち、l_i \leq p \leq r_i-1 かつ S_p = S_{p+1}を満たす整数 p は何個ありますか?
Q 個の質問それぞれの答えを出力してください。
制約
- N, Q は整数
- 1 \leq N, Q \leq 3 \times 10^5
- S は英小文字のみからなる長さ N の文字列
- l_i, r_i は整数
- 1 \leq l_i \leq r_i \leq N
入力
入力は以下の形式で標準入力から与えられる。
N Q S l_1 r_1 l_2 r_2 \vdots l_Q r_Q
出力
Q 行出力せよ。 i = 1, 2, \ldots, Q について、i 行目には i 番目の質問に対する答えを出力せよ。
入力例 1
11 4 mississippi 3 9 4 10 4 6 7 7
出力例 1
2 2 0 0
4 個の質問それぞれに対する答えは下記の通りです。
- 1 個目の質問に関して、S_3S_4\ldots S_9 =  ssissipで同じ英小文字が隣り合う箇所は、S_3S_4 =ssと S_6S_7 =ssの 2 個です。
- 2 個目の質問に関して、S_4S_5\ldots S_{10} =  sissippで同じ英小文字が隣り合う箇所は、S_6S_7 =ssと S_9S_{10} =ppの 2 個です。
- 3 個目の質問に関して、S_4S_5S_6 =  sisで同じ英小文字が隣り合う箇所は 0 個です。
- 4 個目の質問に関して、S_7 =  sで同じ英小文字が隣り合う箇所は 0 個です。
入力例 2
5 1 aaaaa 1 5
出力例 2
4
S_1S_2\ldots S_5 =  aaaaa で同じ英小文字が隣り合う箇所は、
S_1S_2 =  aa 、S_2S_3 =  aa 、S_3S_4 =  aa 、S_4S_5 =  aa の 4 個です。
Score : 300 points
Problem Statement
You are given a string S = S_1S_2\ldots S_N of length N consisting of lowercase English letters.
Additionally, you are given Q queries about the string S. For i = 1, 2, \ldots, Q, the i-th query is represented by two integers l_i, r_i and asks the following.
In the substring S_{l_i}S_{l_i+1}\ldots S_{r_i} of S, which ranges from the l_i-th to the r_i-th character, how many places are there where the same lowercase English letter occurs twice in a row? In other words, how many integers p satisfy l_i \leq p \leq r_i-1 and S_p = S_{p+1}?
Print the answer for each of the Q queries.
Constraints
- N and Q are integers.
- 1 \leq N, Q \leq 3 \times 10^5
- S is a string of length N consisting of lowercase English letters.
- l_i and r_i are integers.
- 1 \leq l_i \leq r_i \leq N
Input
The input is given from Standard Input in the following format:
N Q S l_1 r_1 l_2 r_2 \vdots l_Q r_Q
Output
Print Q lines. For i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th query.
Sample Input 1
11 4 mississippi 3 9 4 10 4 6 7 7
Sample Output 1
2 2 0 0
The answers to the four queries are as follows.
- For the first query, S_3S_4\ldots S_9 =  ssissiphas two places where the same lowercase English letter occurs twice in a row: S_3S_4 =ssand S_6S_7 =ss.
- For the second query, S_4S_5\ldots S_{10} =  sissipphas two places where the same lowercase English letter occurs twice in a row: S_6S_7 =ssand S_9S_{10} =pp.
- For the third query, S_4S_5S_6 =  sishas zero places where the same lowercase English letter occurs twice in a row.
- For the fourth query, S_7 =  shas zero places where the same lowercase English letter occurs twice in a row.
Sample Input 2
5 1 aaaaa 1 5
Sample Output 2
4
S_1S_2\ldots S_5 =  aaaaa has four places where the same lowercase English letter occurs twice in a row:
S_1S_2 =  aa, S_2S_3 =  aa, S_3S_4 =  aa, and S_4S_5 =  aa.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N \times N のマス目が与えられます。このうち上から i 行目、左から j 列目のマスを (i,j) と書きます。
各マスの状態を表す N 個の長さ N の文字列 S_1,S_2,\dots,S_N が以下の形式で与えられます。  
- S_i の j 文字目が oであるとき、 (i,j) にはoが書かれている。
- S_i の j 文字目が xであるとき、 (i,j) にはxが書かれている。
以下の条件を全て満たすマスの三つ組の個数を求めてください。
- 組に含まれる 3 マスは相異なる。
- 3 マス全てに oが書かれている。
- マスのうち、丁度 2 つが同じ行にある。
- マスのうち、丁度 2 つが同じ列にある。
但し、ふたつの三つ組は、丁度一方に含まれるマスが存在する場合のみ区別します。
制約
- N は 2 以上 2000 以下の整数
- S_i は長さ N の oとxからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを整数として出力せよ。
入力例 1
3 ooo oxx xxo
出力例 1
4
以下の 4 つの三つ組が条件を満たします。
- (1,1),(1,2),(2,1)
- (1,1),(1,3),(2,1)
- (1,1),(1,3),(3,3)
- (1,2),(1,3),(3,3)
入力例 2
4 oxxx xoxx xxox xxxo
出力例 2
0
入力例 3
15 xooxxooooxxxoox oxxoxoxxxoxoxxo oxxoxoxxxoxoxxx ooooxooooxxoxxx oxxoxoxxxoxoxxx oxxoxoxxxoxoxxo oxxoxooooxxxoox xxxxxxxxxxxxxxx xooxxxooxxxooox oxxoxoxxoxoxxxo xxxoxxxxoxoxxoo xooxxxooxxoxoxo xxxoxxxxoxooxxo oxxoxoxxoxoxxxo xooxxxooxxxooox
出力例 3
2960
Score : 400 points
Problem Statement
You are given an N \times N grid. Let (i,j) denote the cell in the i-th row from the top and the j-th column from the left.
The states of the cells are given by N strings of length N, S_1, S_2, \dots, S_N, in the following format:
- If the j-th character of S_i is o, there is anowritten in cell (i,j).
- If the j-th character of S_i is x, there is anxwritten in cell (i,j).
Find the number of triples of cells that satisfy all of the following conditions:
- The three cells in the triple are distinct.
- All three cells have an owritten in them.
- Exactly two of the cells are in the same row.
- Exactly two of the cells are in the same column.
Here, two triples are considered different if and only if some cell is contained in exactly one of the triples.
Constraints
- N is an integer between 2 and 2000, inclusive.
- S_i is a string of length N consisting of oandx.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer as an integer.
Sample Input 1
3 ooo oxx xxo
Sample Output 1
4
The following four triples satisfy the conditions:
- (1,1),(1,2),(2,1)
- (1,1),(1,3),(2,1)
- (1,1),(1,3),(3,3)
- (1,2),(1,3),(3,3)
Sample Input 2
4 oxxx xoxx xxox xxxo
Sample Output 2
0
Sample Input 3
15 xooxxooooxxxoox oxxoxoxxxoxoxxo oxxoxoxxxoxoxxx ooooxooooxxoxxx oxxoxoxxxoxoxxx oxxoxoxxxoxoxxo oxxoxooooxxxoox xxxxxxxxxxxxxxx xooxxxooxxxooox oxxoxoxxoxoxxxo xxxoxxxxoxoxxoo xooxxxooxxoxoxo xxxoxxxxoxooxxo oxxoxoxxoxoxxxo xooxxxooxxxooox
Sample Output 3
2960
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
0 から N-1 の番号がついた N 個の箱があります。最初、箱 i には A_i 個のボールが入っています。
高橋君は i=1,2,\ldots,M の順に以下の操作を行います。
- 変数 C を 0 とする。
- 箱 B_i の中のボールを全て取り出し、手に持つ。
- 手にボールを 1 個以上持っている間、次の処理を繰り返す:- C の値を 1 増やす。
- 手に持っているボールを 1 個、箱 (B_i+C) \bmod N に入れる。
 
全ての操作を終えた後、各箱に入っているボールの個数を求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 \leq A_i \leq 10^9
- 0 \leq B_i < N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
A_0 A_1 \ldots A_{N-1}
B_1 B_2 \ldots B_M
出力
全ての操作を終えた後、箱 i に入っているボールの個数を X_i とする。X_0,X_1,\ldots,X_{N-1} をこの順に空白区切りで出力せよ。
入力例 1
5 3 1 2 3 4 5 2 4 0
出力例 1
0 4 2 7 2
操作は次のように進行します。

入力例 2
3 10 1000000000 1000000000 1000000000 0 1 0 1 0 1 0 1 0 1
出力例 2
104320141 45436840 2850243019
入力例 3
1 4 1 0 0 0 0
出力例 3
1
Score: 475 points
Problem Statement
There are N boxes numbered 0 to N-1. Initially, box i contains A_i balls.
Takahashi will perform the following operations for i=1,2,\ldots,M in order:
- Set a variable C to 0.
- Take out all the balls from box B_i and hold them in hand.
- While holding at least one ball in hand, repeat the following process:- Increase the value of C by 1.
- Put one ball from hand into box (B_i+C) \bmod N.
 
Determine the number of balls in each box after completing all operations.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 0 \leq A_i \leq 10^9
- 0 \leq B_i < N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A_0 A_1 \ldots A_{N-1}
B_1 B_2 \ldots B_M
Output
Let X_i be the number of balls in box i after completing all operations. Print X_0,X_1,\ldots,X_{N-1} in this order, separated by spaces.
Sample Input 1
5 3 1 2 3 4 5 2 4 0
Sample Output 1
0 4 2 7 2
The operations proceed as follows:

Sample Input 2
3 10 1000000000 1000000000 1000000000 0 1 0 1 0 1 0 1 0 1
Sample Output 2
104320141 45436840 2850243019
Sample Input 3
1 4 1 0 0 0 0
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
文字列 S が与えられます。S の空でない、連続するとは限らない部分列を並び替えて得られる文字列は何種類ありますか?
答えは非常に大きくなる場合があるので、998244353 で割ったあまりを出力してください。
制約
- S は英小文字のみからなる長さ 1 以上 5000 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の部分列を並び替えて得られる文字列の種類数を 998244353 で割ったあまりを出力せよ。
入力例 1
aab
出力例 1
8
S の部分列を並び替えて得られる文字列は、a, b, aa, ab, ba, aab, aba, baa の 8 種類です。
入力例 2
aaa
出力例 2
3
入力例 3
abcdefghijklmnopqrstuvwxyz
出力例 3
149621752
998244353 で割ったあまりを出力することに注意してください。
Score : 500 points
Problem Statement
Given is a string S. How many different strings can be obtained as a permutation of a non-empty, not necessarily contiguous subsequence of S?
Since the count can be enormous, print it modulo 998244353.
Constraints
- S is a string of length 1 and 5000 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained as a permutation of a subsequence of S, modulo 998244353.
Sample Input 1
aab
Sample Output 1
8
There are 8 different strings that can be obtained as a permutation of a subsequence of S: a, b, aa, ab, ba, aab, aba, baa.
Sample Input 2
aaa
Sample Output 2
3
Sample Input 3
abcdefghijklmnopqrstuvwxyz
Sample Output 3
149621752
Be sure to print the count modulo 998244353.