Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 以上 12 以下の整数 X,Y が与えられます。
X 月の Y ヶ月後が何月か求めてください。
制約
- X,Y は 1 以上 12 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
答えを整数として出力せよ。
入力例 1
5 9
出力例 1
2
5 月の 9 ヶ月後は 2 月です。したがって、 2 を出力してください。
入力例 2
1 1
出力例 2
2
入力例 3
12 12
出力例 3
12
Score : 100 points
Problem Statement
You are given integers X and Y between 1 and 12, inclusive.
Find what month it will be Y months after month X (for example, month 1 is January).
Constraints
- X and Y are integers between 1 and 12, inclusive.
Input
The input is given from Standard Input in the following format:
X Y
Output
Output the answer as an integer.
Sample Input 1
5 9
Sample Output 1
2
Nine months after May is February. Therefore, output 2.
Sample Input 2
1 1
Sample Output 2
2
Sample Input 3
12 12
Sample Output 3
12
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0 か 1 かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0, 1 からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。
各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。
- その回の投票で
0を選択した人が x 人、1を選択した人が y 人いたとします。- x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
- そうでなく x<y である場合、その投票で
0に投票した人のみに 1 点が与えられる。 - そうでない場合、その投票で
1に投票した人のみに 1 点が与えられる。 - なお、 N が奇数であることから x=y となることはないことに留意してください。
M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。
制約
- N は 1 \le N \le 99 を満たす 奇数
- M は 1 \le M \le 100 を満たす整数
- S_i は長さ M の
0,1からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。
入力例 1
3 5 11100 10101 01110
出力例 1
2 3
このケースでは、 3 人が 5 回の投票を行いました。
- 1 回目の投票では人 1 が
1、人 2 が1、人 3 が0に投票しました。よって、人 3 のみが 1 点を得ます。 - 2 回目の投票では人 1 が
1、人 2 が0、人 3 が1に投票しました。よって、人 2 のみが 1 点を得ます。 - 3 回目の投票では人 1 が
1、人 2 が1、人 3 が1に投票しました。よって、全員が 1 点を得ます。 - 4 回目の投票では人 1 が
0、人 2 が0、人 3 が1に投票しました。よって、人 3 のみが 1 点を得ます。 - 5 回目の投票では人 1 が
0、人 2 が1、人 3 が0に投票しました。よって、人 2 のみが 1 点を得ます。
この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。
入力例 2
5 4 0000 0000 0000 0000 0000
出力例 2
1 2 3 4 5
入力例 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
出力例 3
1 2 3
Score : 200 points
Problem Statement
People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0 or 1.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0 and 1, where the j-th character of S_i represents person i's vote content for the j-th vote.
In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:
- Suppose x people chose
0and y people chose1in that vote.- If x=0 or y=0, everyone receives 1 point for that vote.
- Otherwise, if x<y, only people who voted
0in that vote receive 1 point. - Otherwise, only people who voted
1in that vote receive 1 point. - Note that since N is odd, x=y never occurs.
After finishing M votes, find all people who have the highest total score from those votes.
Constraints
- N is an odd number satisfying 1 \le N \le 99.
- M is an integer satisfying 1 \le M \le 100.
- S_i is a string of length M consisting of
0and1.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Output all person numbers with the highest score in ascending order of person number, separated by spaces.
Sample Input 1
3 5 11100 10101 01110
Sample Output 1
2 3
In this case, three people conducted five votes.
- In the 1st vote, person 1 voted
1, person 2 voted1, person 3 voted0. Thus, only person 3 receives 1 point. - In the 2nd vote, person 1 voted
1, person 2 voted0, person 3 voted1. Thus, only person 2 receives 1 point. - In the 3rd vote, person 1 voted
1, person 2 voted1, person 3 voted1. Thus, everyone receives 1 point. - In the 4th vote, person 1 voted
0, person 2 voted0, person 3 voted1. Thus, only person 3 receives 1 point. - In the 5th vote, person 1 voted
0, person 2 voted1, person 3 voted0. Thus, only person 2 receives 1 point.
As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.
Sample Input 2
5 4 0000 0000 0000 0000 0000
Sample Output 2
1 2 3 4 5
Sample Input 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
Sample Output 3
1 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N) が与えられます。
Q 個のクエリが与えられるので順に処理してください。 i 番目 (1\le i\le Q) のクエリは以下で説明されます。
文字 c_i と整数 X_i,V_i が与えられる。 c_i=
Aならば A_{X_i} を、 c_i=Bならば B_{X_i} を V_i に変更する。その後、 \displaystyle \sum_{k=1}^N \min(A_k,B_k) を出力する。
制約
- 1\le N,Q \le 2 \times 10^5
- 1\le A_i,B_i \le 10^9
- c_i は
AかBのいずれか - 1\le X_i \le N
- 1\le V_i \le 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N c_1 X_1 V_1 c_2 X_2 V_2 \vdots c_Q X_Q V_Q
出力
Q 行出力せよ。 i 行目 (1\le i\le Q) には i 番目のクエリに対する答えを出力せよ。
入力例 1
4 3 3 1 4 1 2 7 1 8 A 2 3 B 3 3 A 1 7
出力例 1
7 9 9
1 番目のクエリでは A=(3,3,4,1),B=(2,7,1,8) となります。したがって、1 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 を出力してください。
2 番目のクエリでは A=(3,3,4,1),B=(2,7,3,8) となります。したがって、 2 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。
3 番目のクエリでは A=(7,3,4,1),B=(2,7,3,8) となります。したがって、 3 行目には \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。
入力例 2
1 3 1 1000000000 A 1 1 A 1 1 A 1 1
出力例 2
1 1 1
入力例 3
5 3 100 100 100 100 100 100 100 100 100 100 A 4 21 A 2 99 B 4 57
出力例 3
421 420 420
Score : 300 points
Problem Statement
You are given length-N integer sequences: A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N).
You are given Q queries to process in order. The i-th query (1\le i\le Q) is described as follows:
You are given a character c_i and integers X_i,V_i. If c_i=
A, change A_{X_i} to V_i; if c_i=B, change B_{X_i} to V_i. Then, output \displaystyle \sum_{k=1}^N \min(A_k,B_k).
Constraints
- 1\le N,Q \le 2 \times 10^5
- 1\le A_i,B_i \le 10^9
- c_i is either
AorB. - 1\le X_i \le N
- 1\le V_i \le 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N c_1 X_1 V_1 c_2 X_2 V_2 \vdots c_Q X_Q V_Q
Output
Output Q lines. The i-th line (1\le i\le Q) should contain the answer to the i-th query.
Sample Input 1
4 3 3 1 4 1 2 7 1 8 A 2 3 B 3 3 A 1 7
Sample Output 1
7 9 9
After the 1st query, A=(3,3,4,1),B=(2,7,1,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 on the 1st line.
After the 2nd query, A=(3,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 2nd line.
After the 3rd query, A=(7,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 3rd line.
Sample Input 2
1 3 1 1000000000 A 1 1 A 1 1 A 1 1
Sample Output 2
1 1 1
Sample Input 3
5 3 100 100 100 100 100 100 100 100 100 100 A 4 21 A 2 99 B 4 57
Sample Output 3
421 420 420
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
H 行 W 列のグリッドがあります。上から i 行目、左から j 列目のマス目を (i,j) と表します。各マスの状態は文字 A_{i,j} で表され、意味は以下の通りです。
.:空きマス。#:障害物マス。S:スタートマス。G:ゴールマス。o:開いたドアのマス。x:閉じたドアのマス。?:スイッチマス。
高橋君は、 1 回の操作で今いるマスから上下左右に隣り合う、障害物マスでも閉じたドアでもないマスへ移動することができます。
また、スイッチマスに移動する度に全ての開いたドアのマスは閉じたドアのマスに、閉じたドアのマスは開いたドアのマスに変わります。
高橋君がはじめスタートマスにいる状態からゴールマスにいる状態にするよう操作できるか判定し、可能な場合は必要な操作回数の最小値を求めてください。
制約
- 1\le H,W \le 500
- H,W は整数
- A_{i,j} は
.,#,S,G,o,x,?のいずれか SとGは A_{i,j} にそれぞれちょうど 1 つずつ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W
A_{1,1}A_{1,2}\cdots A_{1,W}
A_{2,1}A_{2,2}\cdots A_{2,W}
\vdots
A_{H,1}A_{H,2}\cdots A_{H,W}
出力
高橋君がはじめスタートマスにいる状態からゴールマスにいる状態するよう操作できる場合は必要な操作回数の最小値を、できない場合は -1 を出力せよ。
入力例 1
2 4 S.xG #?o.
出力例 1
5
(1,1) から順に (1,2),(2,2),(1,2),(1,3),(1,4) と移動するよう操作することで 5 回の操作でゴールマスにいる状態にすることができます。
入力例 2
1 5 So?oG
出力例 2
-1
どのように操作してもゴールマスにいる状態にすることはできません。したがって、 -1 を出力してください。
入力例 3
5 5 Sx?x? o#o#x ?o?o? x#x#o ?x?oG
出力例 3
10
Score : 400 points
Problem Statement
There is a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left. The state of each cell is represented by a character A_{i,j}, with the following meanings:
.: Empty cell.#: Obstacle cell.S: Start cell.G: Goal cell.o: Open door cell.x: Closed door cell.?: Switch cell.
Takahashi can move from his current cell to an adjacent cell (up, down, left, right) that is neither an obstacle cell nor a closed door cell in one operation.
Also, every time he moves to a switch cell, all open door cells become closed door cells, and all closed door cells become open door cells.
Determine whether he can move from the initial state of being at the start cell to being at the goal cell, and if possible, find the minimum number of operations required.
Constraints
- 1\le H,W \le 500
- H and W are integers.
- Each A_{i,j} is one of
.,#,S,G,o,x,?. SandGeach appear exactly once in A_{i,j}.
Input
The input is given from Standard Input in the following format:
H W
A_{1,1}A_{1,2}\cdots A_{1,W}
A_{2,1}A_{2,2}\cdots A_{2,W}
\vdots
A_{H,1}A_{H,2}\cdots A_{H,W}
Output
If Takahashi can move from the initial state of being at the start cell to being at the goal cell, output the minimum number of operations required; otherwise, output -1.
Sample Input 1
2 4 S.xG #?o.
Sample Output 1
5
By moving from (1,1) to (1,2),(2,2),(1,2),(1,3),(1,4) in that order, he can reach the goal cell in five operations.
Sample Input 2
1 5 So?oG
Sample Output 2
-1
No matter how he operates, he cannot reach the goal cell. Therefore, output -1.
Sample Input 3
5 5 Sx?x? o#o#x ?o?o? x#x#o ?x?oG
Sample Output 3
10
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
N 頂点 0 辺の無向グラフが与えられます。
頂点には 1,2,\dots,N の番号が付けられており、最初は全ての頂点が白色です。
以下の 3 種類のクエリを合計 Q 個処理して下さい。
- タイプ 1 : 頂点 u,v を結ぶ無向辺を追加する。
- タイプ 2 : 頂点 v が白色なら黒色に、黒色なら白色に変更する。
- タイプ 3 : 頂点 v から 0 本以上の辺を辿って黒色の頂点に到達できるか判定し、到達できるなら
Yes、到達できないならNoと答える。
制約
- 入力は全て整数
- 1 \le N \le 2 \times 10^5
- 1 \le Q \le 6 \times 10^5
- タイプ 1 のクエリは以下の制約を満たす。
- 1 \le u < v \le N
- 各クエリについて、そのクエリより前に u,v を結ぶ辺は追加されていない。
- タイプ 2,3 のクエリは以下の制約を満たす。
- 1 \le v \le N
入力
入力は以下の形式で標準入力から与えられる。
N Q
\rm{Query}_1
\rm{Query}_2
\vdots
\rm{Query}_Q
但し、 \rm{Query}_i は i 個目のクエリを表す。
タイプ 1 のクエリは以下の形式で与えられる。
1 u v
タイプ 2 のクエリは以下の形式で与えられる。
2 v
タイプ 3 のクエリは以下の形式で与えられる。
3 v
出力
タイプ 3 のクエリが現れる度に、その解答を次の通りに出力せよ。
- 頂点 v から 0 本以上の辺を辿って黒色の頂点に到達できるなら
Yes - 頂点 v から 0 本以上の辺を辿って黒色の頂点に到達できないなら
No
入力例 1
5 12 3 2 2 2 3 2 1 2 5 1 3 4 3 4 3 5 1 4 5 1 1 3 3 1 2 2 3 1
出力例 1
No Yes No Yes Yes No
この入力では、グラフは最初 5 頂点 0 辺です。
この入力には 12 個のクエリが含まれます。
- 1 個目のクエリは
3 2です。- この時点で頂点 2 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
Noと解答します。
- この時点で頂点 2 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
- 2 個目のクエリは
2 2です。- 頂点 2 は白色なので、黒色に変更します。
- 3 個目のクエリは
3 2です。- この時点で頂点 2 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
Yesと解答します。
- この時点で頂点 2 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
- 4 個目のクエリは
1 2 5です。- 頂点 2,5 を結ぶ辺を追加します。
- 5 個目のクエリは
1 3 4です。- 頂点 3,4 を結ぶ辺を追加します。
- 6 個目のクエリは
3 4です。- この時点で頂点 4 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
Noと解答します。
- この時点で頂点 4 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
- 7 個目のクエリは
3 5です。- この時点で頂点 5 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
Yesと解答します。
- この時点で頂点 5 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
- 8 個目のクエリは
1 4 5です。- 頂点 4,5 を結ぶ辺を追加します。
- 9 個目のクエリは
1 1 3です。- 頂点 1,3 を結ぶ辺を追加します。
- 10 個目のクエリは
3 1です。- この時点で頂点 1 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
Yesと解答します。
- この時点で頂点 1 から 0 本以上の辺を辿って黒色の頂点 2 に到達できます。よって、
- 11 個目のクエリは
2 2です。- 頂点 2 は黒色なので、白色に変更します。
- 12 個目のクエリは
3 1です。- この時点で頂点 1 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
Noと解答します。
- この時点で頂点 1 から 0 本以上の辺を辿って黒色の頂点に到達できないので、
Score : 450 points
Problem Statement
You are given an undirected graph with N vertices and zero edges.
The vertices are numbered 1,2,\dots,N, and initially all vertices are white.
Process a total of Q queries of the following three types:
- Type 1 : Add an undirected edge connecting vertices u and v.
- Type 2 : If vertex v is white, change it to black; if it is black, change it to white.
- Type 3 : Determine whether a black vertex can be reached from vertex v by traversing zero or more edges; report
Yesif reachable, andNootherwise.
Constraints
- All input values are integers.
- 1 \le N \le 2 \times 10^5
- 1 \le Q \le 6 \times 10^5
- Type 1 queries satisfy the following constraints:
- 1 \le u < v \le N
- For each query, no edge connecting u and v has been added before that query.
- Type 2,3 queries satisfy the following constraints:
- 1 \le v \le N
Input
The input is given from Standard Input in the following format:
N Q
\rm{Query}_1
\rm{Query}_2
\vdots
\rm{Query}_Q
where \rm{Query}_i represents the i-th query.
Type 1 queries are given in the following format:
1 u v
Type 2 queries are given in the following format:
2 v
Type 3 queries are given in the following format:
3 v
Output
For each type 3 query, output the answer as follows:
Yesif a black vertex can be reached from vertex v by traversing zero or more edges;Noif no black vertex can be reached from vertex v by traversing zero or more edges.
Sample Input 1
5 12 3 2 2 2 3 2 1 2 5 1 3 4 3 4 3 5 1 4 5 1 1 3 3 1 2 2 3 1
Sample Output 1
No Yes No Yes Yes No
In this input, the graph initially has five vertices and zero edges.
This input contains 12 queries.
- The 1st query is
3 2.- At this point, no black vertex can be reached from vertex 2 by traversing zero or more edges, so report
No.
- At this point, no black vertex can be reached from vertex 2 by traversing zero or more edges, so report
- The 2nd query is
2 2.- Vertex 2 is white, so change it to black.
- The 3rd query is
3 2.- At this point, black vertex 2 can be reached from vertex 2 by traversing zero or more edges. Therefore, report
Yes.
- At this point, black vertex 2 can be reached from vertex 2 by traversing zero or more edges. Therefore, report
- The 4th query is
1 2 5.- Add an edge connecting vertices 2,5.
- The 5th query is
1 3 4.- Add an edge connecting vertices 3,4.
- The 6th query is
3 4.- At this point, no black vertex can be reached from vertex 4 by traversing zero or more edges, so report
No.
- At this point, no black vertex can be reached from vertex 4 by traversing zero or more edges, so report
- The 7th query is
3 5.- At this point, black vertex 2 can be reached from vertex 5 by traversing zero or more edges. Therefore, report
Yes.
- At this point, black vertex 2 can be reached from vertex 5 by traversing zero or more edges. Therefore, report
- The 8th query is
1 4 5.- Add an edge connecting vertices 4,5.
- The 9th query is
1 1 3.- Add an edge connecting vertices 1,3.
- The 10th query is
3 1.- At this point, black vertex 2 can be reached from vertex 1 by traversing zero or more edges. Therefore, report
Yes.
- At this point, black vertex 2 can be reached from vertex 1 by traversing zero or more edges. Therefore, report
- The 11th query is
2 2.- Vertex 2 is black, so change it to white.
- The 12th query is
3 1.- At this point, no black vertex can be reached from vertex 1 by traversing zero or more edges, so report
No.
- At this point, no black vertex can be reached from vertex 1 by traversing zero or more edges, so report
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
N \times M のグリッドが与えられます。各マスには . または # が書かれています。
マスに書かれている記号の情報は N 個の文字列 S_1,S_2,\dots,S_N として与えられ、上から i 行目の左から j マス目には S_i の j 文字目と同じ記号が書かれています。
全てのマスに . が書かれており、 K 個以下のマスで構成される長方領域は全部でいくつありますか?
厳密には、以下の条件を満たす整数の組 (l_x,r_x,l_y,r_y) の数を数えてください。
- 1 \le l_x \le r_x \le N
- 1 \le l_y \le r_y \le M
- (r_x-l_x+1) \times (r_y-l_y+1) \le K
- 全ての l_x \le i \le r_x 、 l_y \le j \le r_y を満たす整数組 (i,j) について、上から i 行目の左から j マス目には
.が書かれている。
制約
- N,M,K は整数
- 1 \le N,M \le 5 \times 10^5
- 1 \le N \times M \le 5 \times 10^6
- 1 \le K \le N \times M
- S_i は
.と#からなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M K S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 3 4 #.. ... ..#
出力例 1
19
数えるべき長方領域の数は以下の 19 個です。
- (l_x,r_x,l_y,r_y) = (1,2,2,3) で表現される長方領域
- (l_x,r_x,l_y,r_y) = (2,3,1,2) で表現される長方領域
- (l_x,r_x,l_y,r_y) = (2,2,1,3) で表現される長方領域
- (l_x,r_x,l_y,r_y) = (1,3,2,2) で表現される長方領域
- 縦 1 マス、横 2 マスの
.のみからなる長方領域 4 個 - 縦 2 マス、横 1 マスの
.のみからなる長方領域 4 個 - 縦 1 マス、横 1 マスの
.のみからなる長方領域 7 個
入力例 2
7 5 35 ..... ..... ..... ..... ..... ..... .....
出力例 2
420
入力例 3
10 9 25 #.....#.. ....#.... .......#. ......... .......#. .#....... ......... #........ ........# .#.....#.
出力例 3
984
Score : 550 points
Problem Statement
You are given an N \times M grid. Each cell contains either . or #.
The information about the symbols written in the cells is given as N strings S_1,S_2,\dots,S_N, where the same symbol as the j-th character of S_i is written in the cell at the i-th row from the top and j-th column from the left.
How many rectangular regions consisting of at most K cells have all cells containing .?
Formally, count the number of integer tuples (l_x,r_x,l_y,r_y) that satisfy the following conditions:
- 1 \le l_x \le r_x \le N
- 1 \le l_y \le r_y \le M
- (r_x-l_x+1) \times (r_y-l_y+1) \le K
- For all integer pairs (i,j) satisfying l_x \le i \le r_x and l_y \le j \le r_y, the cell at the i-th row from the top and j-th column from the left contains
..
Constraints
- N, M, and K are integers.
- 1 \le N,M \le 5 \times 10^5
- 1 \le N \times M \le 5 \times 10^6
- 1 \le K \le N \times M
- S_i is a string of length M consisting of
.and#.
Input
The input is given from Standard Input in the following format:
N M K S_1 S_2 \vdots S_N
Output
Output the answer.
Sample Input 1
3 3 4 #.. ... ..#
Sample Output 1
19
The rectangular regions to count are the following 19:
- A rectangular region represented by (l_x,r_x,l_y,r_y) = (1,2,2,3)
- A rectangular region represented by (l_x,r_x,l_y,r_y) = (2,3,1,2)
- A rectangular region represented by (l_x,r_x,l_y,r_y) = (2,2,1,3)
- A rectangular region represented by (l_x,r_x,l_y,r_y) = (1,3,2,2)
- 4 rectangular regions of 1 row and 2 columns consisting only of
. - 4 rectangular regions of 2 rows and 1 column consisting only of
. - 7 rectangular regions of 1 row and 1 column consisting only of
.
Sample Input 2
7 5 35 ..... ..... ..... ..... ..... ..... .....
Sample Output 2
420
Sample Input 3
10 9 25 #.....#.. ....#.... .......#. ......... .......#. .#....... ......... #........ ........# .#.....#.
Sample Output 3
984
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 575 点
問題文
整数 X が与えられます。
\displaystyle \sqrt{n^2+n+X} が整数となるような整数 n を全て求めてください。
制約
- -10^{14} \le X\le 10^{14}
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
\displaystyle \sqrt{n^2+n+X} が整数となるような整数 n を昇順に N_1,N_2,\ldots,N_K (ただし K は条件を満たす n の個数)として、以下の形式で出力せよ。
K N_1 N_2 \ldots N_K
入力例 1
4
出力例 1
4 -4 -1 0 3
\sqrt{n^2+n+4} が整数となる整数 n は n=-4,-1,0,3 の 4 つです。
入力例 2
-10000
出力例 2
8 -10001 -773 -593 -101 100 592 772 10000
入力例 3
20250824
出力例 3
8 -20250824 -4050164 -13304 -884 883 13303 4050163 20250823
Score : 575 points
Problem Statement
You are given an integer X.
Find all integers n such that \displaystyle \sqrt{n^2+n+X} is an integer.
Constraints
- -10^{14} \le X\le 10^{14}
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
X
Output
Let N_1,N_2,\ldots,N_K be the integers n such that \displaystyle \sqrt{n^2+n+X} is an integer, listed in ascending order (where K is the number of n satisfying the condition). Output in the following format:
K N_1 N_2 \ldots N_K
Sample Input 1
4
Sample Output 1
4 -4 -1 0 3
There are four integers n such that \sqrt{n^2+n+4} is an integer: n=-4,-1,0,3.
Sample Input 2
-10000
Sample Output 2
8 -10001 -773 -593 -101 100 592 772 10000
Sample Input 3
20250824
Sample Output 3
8 -20250824 -4050164 -13304 -884 883 13303 4050163 20250823