QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328081 | #833. Cells Blocking | Kazdale | WA | 693ms | 318508kb | C++14 | 2.5kb | 2024-02-15 16:56:36 | 2024-02-15 16:56:36 |
Judging History
answer
#include <iostream>
#include <vector>
#define int long long
using namespace std;
constexpr int MAXN(3007);
vector <int> lmx, lmy;
int xx[] = {0, 1};
int yy[] = {1, 0};
char ch[MAXN][MAXN];
int a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN], d[MAXN][MAXN];
int qx[MAXN * MAXN], qy[MAXN * MAXN], head, tail;
int n, m, ept, jiao, njiao;
long long ans;
inline void read(int &temp) { cin >> temp; }
inline void bfs1() {
head = 1, tail = 0;
qx[++tail] = 1, qy[tail] = 1, a[1][1] = 1;
while (head <= tail) {
int nx = qx[head], ny = qy[head++];
for (int i(0); i < 2; ++i) {
int tx = nx + xx[i], ty = ny + yy[i];
if (tx > n || ty > m || ch[tx][ty] == '*') continue;
if (!a[tx][ty]) qx[++tail] = tx, qy[tail] = ty;
a[tx][ty] = 1;
}
}
}
inline void bfs2() {
head = 1, tail = 0;
qx[++tail] = n, qy[tail] = m, b[n][m] = 1;
while (head <= tail) {
int nx = qx[head], ny = qy[head++];
for (int i(0); i < 2; ++i) {
int tx = nx - xx[i], ty = ny - yy[i];
if (tx < 1 || ty < 1 || ch[tx][ty] == '*') continue;
if (!b[tx][ty]) qx[++tail] = tx, qy[tail] = ty;
b[tx][ty] = 1;
}
}
}
void leftmost(int x, int y, int dt) {
if (dt) ++c[x][y], lmx.emplace_back(x), lmy.emplace_back(y);
if (d[x][y] && !c[x][y]) ++njiao;
if (x == n && y == m) return ;
if (b[x + 1][y]) return leftmost(x + 1, y, dt);
return leftmost(x, y + 1, dt);
}
void rightmost(int x, int y) {
++d[x][y];
if (c[x][y]) ++jiao;
if (x == n && y == m) return ;
if (b[x][y + 1]) return rightmost(x, y + 1);
return rightmost(x + 1, y);
}
void nlm(int x, int y) {
if (d[x][y] && !c[x][y]) ++njiao;
if (x == 1 && y == 1) return ;
if (a[x][y - 1]) return nlm(x, y - 1);
return nlm(x - 1, y);
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
read(n), read(m);
for (int i(1); i <= n; ++i)
for (int j(1); j <= m; ++j) cin >> ch[i][j];
for (int i(1); i <= n; ++i)
for (int j(1); j <= m; ++j) if (ch[i][j] == '.') ++ept;
bfs1(), bfs2();
if (!a[n][m]) return cout << max(ept * (ept - 1) / 2, 0ll) << endl, 0;
leftmost(1, 1, 1), rightmost(1, 1);
ans = jiao * (ept - jiao) + jiao * (jiao - 1) / 2;
for (int i(0); i < (int)lmx.size(); ++i) {
int x = lmx[i], y = lmy[i];
if (d[x][y]) continue;
njiao = 0;
for (int j(1); x - j >= 1 && y + j <= m; ++j) {
if (a[x - j][y + j] && b[x - j][y + j]) {
leftmost(x - j, y + j, 0), nlm(x - j, y + j);
ans += njiao - d[x - j][y + j];
break;
}
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 628ms
memory: 318508kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 645ms
memory: 318212kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 656ms
memory: 317936kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 666ms
memory: 317604kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 690ms
memory: 317352kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 656ms
memory: 316884kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 684ms
memory: 316688kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 656ms
memory: 316520kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 680ms
memory: 316068kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 636ms
memory: 315672kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 693ms
memory: 315200kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 638ms
memory: 281372kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 558ms
memory: 219136kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 73ms
memory: 14972kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 64ms
memory: 12512kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
1 1 *
output:
-1
result:
wrong answer 1st numbers differ - expected: '0', found: '-1'