Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 行 N 列のマス目があり、それぞれのマスは白または黒で塗られています。
マス目の状態は N 個の文字列 S_i で表され、
S_i の j 文字目が # であることはマス目の上から i 行目、左から j 列目のマスが黒く塗られていることを、
. であることは白く塗られていることをさします。
高橋君はこのマス目のうち高々 2 つの白く塗られているマスを選び、黒く塗ることができます。
マス目の中に、黒く塗られたマスが縦、横、ななめのいずれかの向きに 6 つ以上連続するようにできるか判定してください。
ただし、黒く塗られたマスがななめに 6 つ以上連続するとは、N 行 N 列のマス目に完全に含まれる 6 行 6 列のマス目であって、その少なくとも一方の対角線上のマスがすべて黒く塗られているようなものが存在する事をさします。
制約
- 6 \leq N \leq 1000
- \lvert S_i\rvert =N
- S_i は
#と.のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
高々 2 つのマス目を黒く塗ることで条件をみたすようにできるなら Yes を、そうでないならば No を出力せよ。
入力例 1
8 ........ ........ .#.##.#. ........ ........ ........ ........ ........
出力例 1
Yes
上から 3 行目の左から 3, 6 番目のマスを塗ることで横方向に 6 つの黒く塗られたマスを連続させることができます。
入力例 2
6 ###### ###### ###### ###### ###### ######
出力例 2
Yes
高橋君はマス目を新たに黒く塗ることはできませんが、すでにこのマス目は条件をみたしています。
入力例 3
10 .......... #..##..... .......... .......... ....#..... ....#..... .#...#..#. .......... .......... ..........
出力例 3
No
Score : 300 points
Problem Statement
There is a grid with N horizontal rows and N vertical columns, where each square is painted white or black.
The state of the grid is represented by N strings, S_i.
If the j-th character of S_i is #, the square at the i-th row from the top and the j-th column from the left is painted black.
If the character is ., then the square is painted white.
Takahashi can choose at most two of these squares that are painted white, and paint them black.
Determine if it is possible to make the grid contain 6 or more consecutive squares painted black aligned either vertically, horizontally, or diagonally.
Here, the grid is said to be containing 6 or more consecutive squares painted black aligned diagonally if the grid with N rows and N columns completely contains a subgrid with 6 rows and 6 columns such that all the squares on at least one of its diagonals are painted black.
Constraints
- 6 \leq N \leq 1000
- \lvert S_i\rvert =N
- S_i consists of
#and..
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If it is possible to fulfill the condition by painting at most two squares, then print Yes; otherwise, print No.
Sample Input 1
8 ........ ........ .#.##.#. ........ ........ ........ ........ ........
Sample Output 1
Yes
By painting the 3-rd and the 6-th squares from the left in the 3-rd row from the top, there will be 6 squares painted black aligned horizontally.
Sample Input 2
6 ###### ###### ###### ###### ###### ######
Sample Output 2
Yes
While Takahashi cannot choose a square to paint black, the grid already satisfies the condition.
Sample Input 3
10 .......... #..##..... .......... .......... ....#..... ....#..... .#...#..#. .......... .......... ..........
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。
N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X 個 (X>0) 存在するならば、X を文字列として扱って S_i+
(+X+)を出力する。
制約
- 1 \leq N \leq 2\times 10^5
- S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文中の指示にしたがって、N 行出力せよ。
入力例 1
5 newfile newfile newfolder newfile newfolder
出力例 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
入力例 2
11 a a a a a a a a a a a
出力例 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Score : 300 points
Problem Statement
For two strings A and B, let A+B denote the concatenation of A and B in this order.
You are given N strings S_1,\ldots,S_N. Modify and print them as follows, in the order i=1, \ldots, N:
- if none of S_1,\ldots,S_{i-1} is equal to S_i, print S_i;
- if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i, print S_i+
(+X+), treating X as a string.
Constraints
- 1 \leq N \leq 2\times 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines as specified in the Problem Statement.
Sample Input 1
5 newfile newfile newfolder newfile newfolder
Sample Output 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
Sample Input 2
11 a a a a a a a a a a a
Sample Output 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は N 枚のカードを手札として持っています。 i = 1, 2, \ldots, N について、i 番目のカードには非負整数 A_i が書かれています。
高橋君は、まず手札から好きなカードを 1 枚選んで、テーブルの上に置きます。 その後、高橋君は好きな回数( 0 回でも良い)だけ、下記の操作を繰り返します。
- 最後にテーブルの上に置いたカードに書かれた整数を X とする。手札に整数 X または整数 (X+1)\bmod M が書かれたカードがあれば、そのうち好きなものを 1 枚選んで、テーブルの上に置く。ここで、(X+1)\bmod M は (X+1) を M で割ったあまりを表す。
最終的に手札に残ったカードに書かれている整数の総和としてあり得る最小値を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 2 \leq M \leq 10^9
- 0 \leq A_i \lt M
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
9 7 3 0 2 5 5 3 0 6 3
出力例 1
11
高橋君が、まず 4 番目のカード(書かれた整数は 5 )をテーブルの上に置き、その後、以下の手順で操作を行う場合を考えます。
- 5 番目のカード(書かれた整数は 5 )をテーブルの上に置く。
- 8 番目のカード(書かれた整数は 6 )をテーブルの上に置く。
- 2 番目のカード(書かれた整数は 0 )をテーブルの上に置く。
- 7 番目のカード(書かれた整数は 0 )をテーブルの上に置く。
このとき、最終的に手札に残ったカードは、1, 3, 6, 9 枚目のカードであり、それらに書かれた整数の総和は 3 + 2 + 3 +3 = 11 です。 これが、最終的に手札に残ったカードに書かれている整数の総和としてあり得る最小値です。
入力例 2
1 10 4
出力例 2
0
入力例 3
20 20 18 16 15 9 8 8 17 1 3 17 11 9 12 11 7 3 2 14 3 12
出力例 3
99
Score : 400 points
Problem Statement
Takahashi has N cards in his hand. For i = 1, 2, \ldots, N, the i-th card has an non-negative integer A_i written on it.
First, Takahashi will freely choose a card from his hand and put it on a table. Then, he will repeat the following operation as many times as he wants (possibly zero).
- Let X be the integer written on the last card put on the table. If his hand contains cards with the integer X or the integer (X+1)\bmod M written on them, freely choose one of those cards and put it on the table. Here, (X+1)\bmod M denotes the remainder when (X+1) is divided by M.
Print the smallest possible sum of the integers written on the cards that end up remaining in his hand.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 2 \leq M \leq 10^9
- 0 \leq A_i \lt M
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
9 7 3 0 2 5 5 3 0 6 3
Sample Output 1
11
Assume that he first puts the fourth card (5 is written) on the table and then performs the following.
- Put the fifth card (5 is written) on the table.
- Put the eighth card (6 is written) on the table.
- Put the second card (0 is written) on the table.
- Put the seventh card (0 is written) on the table.
Then, the first, third, sixth, and ninth cards will end up remaining in his hand, and the sum of the integers on those cards is 3 + 2 + 3 +3 = 11. This is the minimum possible sum of the integers written on the cards that end up remaining in his hand.
Sample Input 2
1 10 4
Sample Output 2
0
Sample Input 3
20 20 18 16 15 9 8 8 17 1 3 17 11 9 12 11 7 3 2 14 3 12
Sample Output 3
99
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
全ての要素が 0 で初期化された長さ N の整数列 A=(A_1,A_2,\ldots,A_N) があります。また、集合 S があります。はじめ S は空です。
以下の Q 個のクエリを順に行います。Q 個のクエリを全て処理した後の数列 A の各要素の値を求めてください。 i 番目のクエリは以下の形式です。
- 整数 x_i が与えられる。整数 x_i が S に含まれる場合、S から x_i を削除する。そうでない場合、S に x_i を追加する。次に、j=1,2,\ldots,N について、j\in S ならば A_j に |S| を加算する。
なお、|S| は集合 S の要素数を意味します。例えば S=\lbrace 3,4,7\rbrace のとき、|S|=3 です。
制約
- 1\leq N,Q\leq 2\times10^5
- 1\leq x_i\leq N
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q x_1 x_2 \ldots x_Q
出力
クエリを全て処理した後の数列 A を以下の形式で出力せよ。
A_1 A_2 \ldots A_N
入力例 1
3 4 1 3 3 2
出力例 1
6 2 2
1 番目のクエリでは、S に 1 を追加し、S=\lbrace 1\rbrace となります。その後、A_1 に |S|=1 を加算します。A=(1,0,0) となります。
2 番目のクエリでは、S に 3 を追加し、S=\lbrace 1,3\rbrace となります。その後、A_1,A_3 に |S|=2 を加算します。A=(3,0,2) となります。
3 番目のクエリでは、S から 3 を削除し、S=\lbrace 1\rbrace となります。その後、A_1 に |S|=1 を加算します。A=(4,0,2) となります。
4 番目のクエリでは、S に 2 を追加し、S=\lbrace 1,2\rbrace となります。その後、A_1,A_2 に |S|=2 を加算します。A=(6,2,2) となります。
最終的に、A=(6,2,2) となります。
入力例 2
4 6 1 2 3 2 4 2
出力例 2
15 9 12 7
Score: 500 points
Problem Statement
There is an integer sequence A=(A_1,A_2,\ldots,A_N) of length N, where all elements are initially set to 0. Also, there is a set S, which is initially empty.
Perform the following Q queries in order. Find the value of each element in the sequence A after processing all Q queries. The i-th query is in the following format:
- An integer x_i is given. If the integer x_i is contained in S, remove x_i from S. Otherwise, insert x_i to S. Then, for each j=1,2,\ldots,N, add |S| to A_j if j\in S.
Here, |S| denotes the number of elements in the set S. For example, if S=\lbrace 3,4,7\rbrace, then |S|=3.
Constraints
- 1\leq N,Q\leq 2\times10^5
- 1\leq x_i\leq N
- All given numbers are integers.
Input
The input is given from Standard Input in the following format:
N Q x_1 x_2 \ldots x_Q
Output
Print the sequence A after processing all queries in the following format:
A_1 A_2 \ldots A_N
Sample Input 1
3 4 1 3 3 2
Sample Output 1
6 2 2
In the first query, 1 is inserted to S, making S=\lbrace 1\rbrace. Then, |S|=1 is added to A_1. The sequence becomes A=(1,0,0).
In the second query, 3 is inserted to S, making S=\lbrace 1,3\rbrace. Then, |S|=2 is added to A_1 and A_3. The sequence becomes A=(3,0,2).
In the third query, 3 is removed from S, making S=\lbrace 1\rbrace. Then, |S|=1 is added to A_1. The sequence becomes A=(4,0,2).
In the fourth query, 2 is inserted to S, making S=\lbrace 1,2\rbrace. Then, |S|=2 is added to A_1 and A_2. The sequence becomes A=(6,2,2).
Eventually, the sequence becomes A=(6,2,2).
Sample Input 2
4 6 1 2 3 2 4 2
Sample Output 2
15 9 12 7
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
以下で説明されるクエリを与えられる順に Q 個処理してください。
クエリは次の 2 種類のいずれかです。
1 x c: S の x 文字目を英小文字 c に変更する。2 L R: S の L 文字目から R 文字目までからなる部分文字列が回文であるならばYesを、そうでないならばNoを出力する。
制約
- 1 \leq N \leq 10^6
- 1 \leq Q \leq 10^5
- S は英小文字からなる長さ N の文字列
- 1 \leq x \leq N
- c は英小文字
- 1 \leq L \leq R \leq N
- N, Q, x, L, R は整数
入力
入力は以下の形式で標準入力から与えられる。ここで \text{query}_i は i 番目に処理するクエリである。
N Q
S
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
各クエリは以下のいずれかの形式で与えられる。
1 x c
2 L R
出力
問題文の指示に従ってクエリへの答えを改行区切りで出力せよ。
入力例 1
7 8 abcbacb 2 1 5 2 4 7 2 2 2 1 5 c 2 1 5 2 4 7 1 4 c 2 3 6
出力例 1
Yes No Yes No Yes Yes
はじめ、S = abcbacb です。
1 番目のクエリについて、S の 1 文字目から 5 文字目までからなる文字列は abcba で、これは回文です。よって Yes を出力します。
2 番目のクエリについて、S の 4 文字目から 7 文字目までからなる文字列は bacb で、これは回文ではありません。よって No を出力します。
3 番目のクエリについて、S の 2 文字目から 2 文字目までからなる文字列は b で、これは回文です。よって Yes を出力します。
4 番目のクエリについて、S の 5 文字目を c に変更します。S は abcbccb になります。
5 番目のクエリについて、S の 1 文字目から 5 文字目までからなる文字列は abcbc で、これは回文ではありません。よって No を出力します。
6 番目のクエリについて、S の 4 文字目から 7 文字目までからなる文字列は bccb で、これは回文です。よって Yes を出力します。
7 番目のクエリについて、S の 4 文字目を c に変更します。S は abccccb になります。
8 番目のクエリについて、S の 3 文字目から 6 文字目までからなる文字列は cccc で、これは回文です。よって Yes を出力します。
Score : 525 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
Process Q queries described below in the order they are given.
There are two types of queries:
1 x c: Change the x-th character of S to the lowercase English letter c.2 L R: If the substring formed by the L-th through R-th characters of S is a palindrome, printYes; otherwise, printNo.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq Q \leq 10^5
- S is a string of length N consisting of lowercase English letters.
- 1 \leq x \leq N
- c is a lowercase English letter.
- 1 \leq L \leq R \leq N
- N, Q, x, L, R are integers.
Input
The input is given from Standard Input in the following format. Here, \text{query}_i is the i-th query to be processed.
N Q
S
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Each query is given in one of the following formats:
1 x c
2 L R
Output
Follow the instructions in the problem statement and print the answers to the queries, separated by newlines.
Sample Input 1
7 8 abcbacb 2 1 5 2 4 7 2 2 2 1 5 c 2 1 5 2 4 7 1 4 c 2 3 6
Sample Output 1
Yes No Yes No Yes Yes
Initially, S = abcbacb.
For the first query, the string formed by the 1-st through 5-th characters of S is abcba, which is a palindrome. Thus, print Yes.
For the second query, the string formed by the 4-th through 7-th character of S is bacb, which is not a palindrome. Thus, print No.
For the third query, the string formed by the 2-nd through 2-nd character of S is b, which is a palindrome. Thus, output Yes.
For the fourth query, change the 5-th character of S to c. S becomes abcbccb.
For the fifth query, the string formed by the 1-st through 5-th character of S is abcbc, which is not a palindrome. Thus, output No.
For the sixth query, the string formed by the 4-th through 7-th character of S is bccb, which is a palindrome. Thus, output Yes.
For the seventh query, change the 4-th character of S to c. S becomes abccccb.
For the eighth query, the string formed by the 3-rd through 6-th character of cccc, which is a palindrome. Thus, output Yes.