Submission #8811583
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
char board[2020][2020];
LL rX[2020][2020], maxRx[2020][2020], cX[2020][2020], maxCx[2020][2020];
int main(){
// 1. 入力情報.
int N, M;
scanf("%d %d", &N, &M);
rep(i, N){
char c[2020];
scanf("%s", c);
rep(j, M) board[i + 1][j + 1] = c[j];
}
// repx(i, 1, N + 1){
// repx(j, 1, M + 1) printf("%c", board[i][j]);
// printf("\n");
// }
// 2. 障害物が無いマスが連続して何個並んでいるかカウント.
// 2-1. 行方向(カウント).
repx(i, 1, N + 1){
repx(j, 1, M + 1){
if(board[i][j] == '.') rX[i][j] = rX[i][j - 1] + 1;
}
}
// 2-2. 行方向(最大値の保存).
repx(i, 1, N + 1){
repr(j, M, 1){
maxRx[i][j] = max(maxRx[i][j + 1], rX[i][j]);
if(board[i][j] == '#') maxRx[i][j] = 0;
}
}
// rep(i, N + 1){
// rep(j, M + 1) printf("%d ", rX[i][j]);
// printf("\n");
// }
// rep(i, N + 1){
// rep(j, M + 1) printf("%d ", maxRx[i][j]);
// printf("\n");
// }
// 2-3. 列方向(カウント).
repx(j, 1, M + 1){
repx(i, 1, N + 1){
if(board[i][j] == '.') cX[i][j] = cX[i - 1][j] + 1;
}
}
// 2-4. 列方向(最大値の保存).
repx(j, 1, M + 1){
repr(i, N, 1){
maxCx[i][j] = max(maxCx[i + 1][j], cX[i][j]);
if(board[i][j] == '#') maxCx[i][j] = 0;
}
}
// rep(i, N + 1){
// rep(j, M + 1) printf("%d ", cX[i][j]);
// printf("\n");
// }
// rep(i, N + 1){
// rep(j, M + 1) printf("%d ", maxCx[i][j]);
// printf("\n");
// }
// 3. 各セルについて, 四方向集計し, 総和を計算.
LL ans = 0;
repx(i, 1, N + 1){
repx(j, 1, M + 1){
// セルが, 障害物の場合は, Skip.
if(board[i][j] == '#') continue;
// 下 -> セル(i, j) -> 右.
ans += (maxCx[i][j] - cX[i][j]) * (maxRx[i][j] - rX[i][j]);
// 左 -> セル(i, j) -> 下.
ans += rX[i][j - 1] * (maxCx[i][j] - cX[i][j]);
// 上 -> セル(i, j) -> 左.
ans += cX[i - 1][j] * rX[i][j - 1];
// 右 -> セル(i, j) -> 上.
ans += (maxRx[i][j] - rX[i][j]) * cX[i - 1][j];
}
}
// 4. 出力.
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 右折 |
User |
at_abcde |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2793 Byte |
Status |
AC |
Exec Time |
167 ms |
Memory |
131712 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:14:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
^
./Main.cpp:17:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", c);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
167 ms |
131712 KB |
02.txt |
AC |
167 ms |
131712 KB |
03.txt |
AC |
167 ms |
131712 KB |
04.txt |
AC |
166 ms |
131712 KB |
05.txt |
AC |
124 ms |
131712 KB |
06.txt |
AC |
123 ms |
131712 KB |
07.txt |
AC |
122 ms |
131712 KB |
08.txt |
AC |
123 ms |
131712 KB |
09.txt |
AC |
121 ms |
131712 KB |
10.txt |
AC |
122 ms |
131712 KB |
11.txt |
AC |
124 ms |
131712 KB |
12.txt |
AC |
124 ms |
131712 KB |
13.txt |
AC |
116 ms |
131712 KB |
14.txt |
AC |
117 ms |
131712 KB |
15.txt |
AC |
122 ms |
131712 KB |
16.txt |
AC |
122 ms |
131712 KB |
17.txt |
AC |
80 ms |
70272 KB |
18.txt |
AC |
79 ms |
70272 KB |
19.txt |
AC |
111 ms |
131712 KB |
20.txt |
AC |
111 ms |
131712 KB |
21.txt |
AC |
125 ms |
131712 KB |
22.txt |
AC |
124 ms |
131712 KB |
23.txt |
AC |
124 ms |
131712 KB |
24.txt |
AC |
124 ms |
131712 KB |
25.txt |
AC |
122 ms |
131712 KB |
26.txt |
AC |
122 ms |
131712 KB |
27.txt |
AC |
123 ms |
131712 KB |
28.txt |
AC |
122 ms |
131712 KB |
29.txt |
AC |
3 ms |
8448 KB |
30.txt |
AC |
3 ms |
8448 KB |
31.txt |
AC |
3 ms |
8448 KB |
32.txt |
AC |
3 ms |
8448 KB |
33.txt |
AC |
3 ms |
8448 KB |
34.txt |
AC |
2 ms |
4352 KB |
35.txt |
AC |
3 ms |
8448 KB |
36.txt |
AC |
3 ms |
8448 KB |
s1.txt |
AC |
3 ms |
8448 KB |
s2.txt |
AC |
3 ms |
8448 KB |
s3.txt |
AC |
3 ms |
8448 KB |