実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
N 行 N 列からなるグリッドがあります。グリッドの上から i 行目左から j 列目のマスは、S_{i,j} が # のとき黒く、. のとき白く塗られています。
このグリッドから縦 M 行横 M 列の領域を取り出して得られるマスの塗られ方は何種類ありますか?
制約
- 1\leq M \leq N \leq 10
- N,M は整数
- S_{i,j} は
.または#
入力
入力は以下の形式で標準入力から与えられる。
N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}
出力
答えを出力せよ。
入力例 1
3 2 ... ### #.#
出力例 1
3
与えられたグリッドの状態は下図左のとおりです。
ここから縦 2 行横 2 列の領域を取り出す方法は下図右のとおり 4 通りあり、マスの塗られ方は 3 種類あります。

入力例 2
10 3 ..#....... .###...... .#.#...... #####..... #...#..... ......#### ......#..# ......#... ......#..# ......####
出力例 2
36
Score : 250 points
Problem Statement
There is a grid with N rows and N columns. The cell at the i-th row from the top and j-th column from the left is painted black if S_{i,j} is #, and white if it is ..
How many distinct patterns of painted cells can be obtained by extracting a region of M rows and M columns from this grid?
Constraints
- 1\leq M \leq N \leq 10
- N and M are integers.
- S_{i,j} is
.or#.
Input
The input is given from Standard Input in the following format:
N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}
Output
Print the answer.
Sample Input 1
3 2 ... ### #.#
Sample Output 1
3
The state of the given grid is as shown in the left figure below.
There are four ways to extract a region of two rows and two columns from this grid as shown in the right figure below, and there are three distinct patterns of painted cells.

Sample Input 2
10 3 ..#....... .###...... .#.#...... #####..... #...#..... ......#### ......#..# ......#... ......#..# ......####
Sample Output 2
36
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
連長圧縮(ランレングス圧縮)を復元してください。ただし、長すぎる場合には
Too Longと出力してください。
N 個の文字と整数の組 (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N) が与えられます。
l_1 個の文字 c_1、l_2 個の文字 c_2、\ldots、l_N 個の文字 c_N をこの順に連結させた文字列を S とします。
S を出力してください。ただし、S の長さが 100 を超える場合には代わりに Too Long と出力してください。
制約
- 1\leq N\leq 100
- 1\leq l_i\leq 10^{18}
- N,l_i は整数
- c_i は英小文字
- c_i\neq c_{i+1}
入力
入力は以下の形式で標準入力から与えられる。
N c_1 l_1 c_2 l_2 \vdots c_N l_N
出力
S の長さが 100 以下なら S を、そうでないなら Too Long と出力せよ。
入力例 1
8 m 1 i 1 s 2 i 1 s 2 i 1 p 2 i 1
出力例 1
mississippi
S は mississippi です。S の長さは 100 以下であるため S を出力します。
入力例 2
7 a 1000000000000000000 t 1000000000000000000 c 1000000000000000000 o 1000000000000000000 d 1000000000000000000 e 1000000000000000000 r 1000000000000000000
出力例 2
Too Long
S の長さは 7\times 10^{18} であるため、Too Long を出力します。
入力例 3
1 a 100
出力例 3
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
入力例 4
6 g 4 j 1 m 4 e 4 d 3 i 4
出力例 4
ggggjmmmmeeeedddiiii
Score : 200 points
Problem Statement
Restore run-length encoding. If the result is too long, output
Too Long.
You are given N pairs of characters and integers (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N).
Let S be the string formed by concatenating l_1 characters c_1, l_2 characters c_2, \ldots, and l_N characters c_N in this order.
Output S. However, if the length of S exceeds 100, output Too Long instead.
Constraints
- 1\leq N\leq 100
- 1\leq l_i\leq 10^{18}
- N and l_i are integers.
- Each c_i is a lowercase English letter.
- c_i\neq c_{i+1}
Input
The input is given from Standard Input in the following format:
N c_1 l_1 c_2 l_2 \vdots c_N l_N
Output
If the length of S is at most 100, output S; otherwise, output Too Long.
Sample Input 1
8 m 1 i 1 s 2 i 1 s 2 i 1 p 2 i 1
Sample Output 1
mississippi
S is mississippi. Since the length of S is not greater than 100, output S.
Sample Input 2
7 a 1000000000000000000 t 1000000000000000000 c 1000000000000000000 o 1000000000000000000 d 1000000000000000000 e 1000000000000000000 r 1000000000000000000
Sample Output 2
Too Long
The length of S is 7\times 10^{18}, so output Too Long.
Sample Input 3
1 a 100
Sample Output 3
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Sample Input 4
6 g 4 j 1 m 4 e 4 d 3 i 4
Sample Output 4
ggggjmmmmeeeedddiiii
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
非負整数 N が与えられるので、以下の条件を満たす非負整数 x を昇順に全て出力してください。
- x を 2 進数として表記した時に 1 となる位の集合が、 N を 2 進数として表記した時に 1 となる位の集合の部分集合となる。
- すなわち、全ての非負整数 k について、「 x の 2^k の位が 1 ならば、 N の 2^k の位は 1 」が成り立つ。
制約
- N は整数
- 0 \le N < 2^{60}
- N を 2 進数として表記した時、 1 となる位は 15 個以下である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを 1 行に 1 つずつ、10 進法の整数として昇順に出力せよ。
入力例 1
11
出力例 1
0 1 2 3 8 9 10 11
N = 11_{(10)} を 2 進数で表記すると、 1011_{(2)} となります。
条件を満たす非負整数 x は以下の通りです。
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
入力例 2
0
出力例 2
0
入力例 3
576461302059761664
出力例 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
入力は 32bit 符号付き整数に収まらない可能性があります。
Score : 300 points
Problem Statement
You are given a non-negative integer N. Print all non-negative integers x that satisfy the following condition in ascending order.
- The set of the digit positions containing 1 in the binary representation of x is a subset of the set of the digit positions containing 1 in the binary representation of N.
- That is, the following holds for every non-negative integer k: if the digit in the "2^ks" place of x is 1, the digit in the 2^ks place of N is 1.
Constraints
- N is an integer.
- 0 \le N < 2^{60}
- In the binary representation of N, at most 15 digit positions contain 1.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer as decimal integers in ascending order, each in its own line.
Sample Input 1
11
Sample Output 1
0 1 2 3 8 9 10 11
The binary representation of N = 11_{(10)} is 1011_{(2)}.
The non-negative integers x that satisfy the condition are:
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
Sample Input 2
0
Sample Output 2
0
Sample Input 3
576461302059761664
Sample Output 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
The input may not fit into a 32-bit signed integer.
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
正整数 x,y に対して f(x,y) を以下で定義します。
- 十進表記の x,y をそれぞれ文字列として解釈しこの順に連結して得られる文字列を z とする。z を十進表記の整数として解釈したときの値を f(x,y) とする。
例えば f(3,14)=314, f(100,1)=1001 です。
長さ N の正整数列 A=(A_1,\ldots,A_N) が与えられます。次の式の値を 998244353 で割ったあまりを求めてください。
制約
- 2\leq N\leq 2\times 10^5
- 1\leq A_i \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 3 14 15
出力例 1
2044
- f(A_1,A_2)=314
- f(A_1,A_3)=315
- f(A_2,A_3)=1415
なので、答えは f(A_1,A_2)+f(A_1,A_3)+f(A_2,A_3) = 2044 です。
入力例 2
5 1001 5 1000000 1000000000 100000
出力例 2
625549048
式の値を 998244353 で割ったあまりを求めることに注意してください。
Score: 400 points
Problem Statement
For positive integers x and y, define f(x, y) as follows:
- Interpret the decimal representations of x and y as strings and concatenate them in this order to obtain a string z. The value of f(x, y) is the value of z when interpreted as a decimal integer.
For example, f(3, 14) = 314 and f(100, 1) = 1001.
You are given a sequence of positive integers A = (A_1, \ldots, A_N) of length N. Find the value of the following expression modulo 998244353:
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
3 3 14 15
Sample Output 1
2044
- f(A_1, A_2) = 314
- f(A_1, A_3) = 315
- f(A_2, A_3) = 1415
Thus, the answer is f(A_1, A_2) + f(A_1, A_3) + f(A_2, A_3) = 2044.
Sample Input 2
5 1001 5 1000000 1000000000 100000
Sample Output 2
625549048
Be sure to calculate the value modulo 998244353.