QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592087 | #833. Cells Blocking | SunsetGlow95 | WA | 264ms | 118560kb | C++14 | 2.4kb | 2024-09-26 20:36:18 | 2024-09-26 20:36:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MXN = 3005;
int N, M, V, luc[MXN][MXN], ldc[MXN][MXN], rc[MXN * 2], bp;
short rn[MXN][MXN], ln[MXN][MXN];
bool mat[MXN][MXN];
long long ans;
int main() {
scanf("%d%d", &N, &M);
for (int i(0); i != N; ++i) {
char c(0);
for (int j(0); j != M; ++j) {
scanf(" %c", &c);
V += mat[i][j] = (c == '.');
}
}
rn[N - 1][M - 1] = ln[N - 1][M - 1] = (mat[N - 1][M - 1] ? 2 : -1);
for (int i(N - 1); ~i; --i) {
for (int j(M - 1 - (i == N - 1)); ~j; --j) {
if (!mat[i][j]) {
ln[i][j] = rn[i][j] = -1;
continue;
}
if (j + 1 != M && ~rn[i][j + 1]) rn[i][j] = 0;
else if (i + 1 != N && ~rn[i + 1][j]) rn[i][j] = 1;
else rn[i][j] = -1;
if (i + 1 != N && ~ln[i + 1][j]) ln[i][j] = 1;
else if (j + 1 != M && ~ln[i][j + 1]) ln[i][j] = 0;
else ln[i][j] = -1;
}
}
//for (int i(0); i != N; ++i) {
// for (int j(0); j != M; ++j) {
// cout << ln[i][j] << ' ';
// }
// cout << endl;
//}
//cout << endl;
//for (int i(0); i != N; ++i) {
// for (int j(0); j != M; ++j) {
// cout << rn[i][j] << ' ';
// }
// cout << endl;
//}
//cout << endl;
if (ln[0][0] == -1) {
printf("%lld\n", V * 1LL * (V - 1) / 2);
return 0;
}
for (int x(0), y(0);;) {
rc[x + y] = x;
if (rn[x][y] == 2) break;
if (rn[x][y] == 1) ++x;
else ++y;
}
ldc[N - 1][M - 1] = 1;
for (int i(N - 1); ~i; --i) {
for (int j(M - 1 - (i == N - 1)); ~j; --j) {
if (ln[i][j] == -1) continue;
ldc[i][j] = (ln[i][j] ? ldc[i + 1][j] : ldc[i][j + 1])
+ (rc[i + j] == i);
}
}
luc[0][0] = 1;
for (int i(0); i != N; ++i) {
for (int j(i == 0); j != M; ++j) {
if (ln[i][j] == -1) continue;
luc[i][j] = (j && ~ln[i][j - 1] ? luc[i][j - 1] : luc[i - 1][j])
+ (rc[i + j] == i);
}
}
for (int x(0), y(0);;) {
if (rc[x + y] == x) ++bp;
else {
int yy(y + 1);
while (ln[x + y - yy][yy] == -1) ++yy;
int xx(x + y - yy);
ans += luc[xx][yy] + ldc[xx][yy] - (rc[x + y] == xx);
}
// cout << x << ' ' << y << ' ' << ans << ' ' << bp << endl;
if (ln[x][y] == 2) break;
if (ln[x][y] == 1) ++x;
else ++y;
}
printf("%lld\n", ans + bp * 1LL * (V - N - M + 1) + bp * 1LL * (bp - 1) / 2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 12048kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 0ms
memory: 12116kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 8060kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7920kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 8084kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 251ms
memory: 118560kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: -100
Wrong Answer
time: 264ms
memory: 118368kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17976238
result:
wrong answer 1st numbers differ - expected: '17981671', found: '17976238'