QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592238#833. Cells BlockingcaijianhongAC ✓355ms110072kbC++233.0kb2024-09-26 21:24:222024-09-26 21:24:22

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 21:24:22]
  • 评测
  • 测评结果:AC
  • 用时:355ms
  • 内存:110072kb
  • [2024-09-26 21:24:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
int n, m, a[3010][3010], vse[3010][3010], vnw[3010][3010], cntf;
LL ans = 0;
int main() {
#ifndef LOCAL
  cin.tie(nullptr)->sync_with_stdio(false);  
#endif
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    static char buf[3010];
    cin >> buf;
    for (int j = 1; j <= m; j++) a[i][j] = buf[j - 1] == '*', cntf += !a[i][j];
  }
  queue<pair<int, int>> q;
  if (!a[1][1]) vse[1][1] = true, q.emplace(1, 1);
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second; q.pop();
    if (x < n && !a[x + 1][y] && !vse[x + 1][y]) vse[x + 1][y] = true, q.emplace(x + 1, y);
    if (y < m && !a[x][y + 1] && !vse[x][y + 1]) vse[x][y + 1] = true, q.emplace(x, y + 1);
  }
  if (!a[n][m]) vnw[n][m] = true, q.emplace(n, m);
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second; q.pop();
    if (x > 1 && !a[x - 1][y] && !vnw[x - 1][y]) vnw[x - 1][y] = true, q.emplace(x - 1, y);
    if (y > 1 && !a[x][y - 1] && !vnw[x][y - 1]) vnw[x][y - 1] = true, q.emplace(x, y - 1);
  }
  if (!vse[n][m]) return cout << 1ll * (cntf - 1) * cntf / 2 << endl, 0;
  vector<pair<int, int>> Lp, Rp;
  for (int x = 1, y = 1; x + y <= n + m; vnw[x + 1][y] ? ++x : ++y) Lp.emplace_back(x, y);
  for (int x = 1, y = 1; x + y <= n + m; vnw[x][y + 1] ? ++y : ++x) Rp.emplace_back(x, y);
#ifdef LOCALx
  debug("LP: ");
  for (int i = 0; i < n + m - 1; i++) debug("(%d, %d) ->%c", Lp[i].first, Lp[i].second, " \n"[i == n + m - 2]);
  debug("RP: ");
  for (int i = 0; i < n + m - 1; i++) debug("(%d, %d) ->%c", Rp[i].first, Rp[i].second, " \n"[i == n + m - 2]);
#endif
  for (int i = 0; i < n + m - 1; i++) if (Lp[i] == Rp[i]) ans += --cntf, debug("all-kill (%d, %d)\n", Lp[i].first, Lp[i].second);
  for (int i = 0; i < n + m - 1; i++) if (Lp[i] != Rp[i]) {
#ifdef LOCALx
    debug("block Lp[%d] = (%d, %d)\n", i, Lp[i].first, Lp[i].second);
#endif
    int x, y; tie(x, y) = Lp[i];
    vector<pair<int, int>> L2(n + m - 1);
    --x, ++y;
    while (!vse[x][y] || !vnw[x][y]) --x, ++y;
    assert(x >= 1 && y <= m);
    for (int j = i, nx = x, ny = y; j >= 0; j--, vse[nx][ny - 1] ? --ny : --nx) L2[j] = make_pair(nx, ny);
    for (int j = i, nx = x, ny = y; j < n + m - 1; j++, vnw[nx + 1][ny] ? ++nx : ++ny) L2[j] = make_pair(nx, ny);
#ifdef LOCALx
  debug("L2: ");
  for (int i = 0; i < n + m - 1; i++) debug("(%d, %d) ->%c", L2[i].first, L2[i].second, " \n"[i == n + m - 2]);
  debug("RP: ");
  for (int i = 0; i < n + m - 1; i++) debug("(%d, %d) ->%c", Rp[i].first, Rp[i].second, " \n"[i == n + m - 2]);
#endif
    for (int j = 0; j < n + m - 1; j++) if (Lp[j] != Rp[j] && L2[j] == Rp[j]) {
      ans += 1;
#ifdef LOCAL
      auto lhs = Lp[i], rhs = L2[j];
      if (lhs > rhs) swap(lhs, rhs);
      debug("couple (%d, %d) & (%d, %d)\n", lhs.first, lhs.second, rhs.first, rhs.second);
#endif
    }
  }
  cout << ans << endl;
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7968kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7628kb

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5672kb

input:

3 4
****
....
****

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 0ms
memory: 5620kb

input:

5 5
*....
.*.*.
*****
*.***
..*..

output:

66

result:

ok 1 number(s): "66"

Test #5:

score: 0
Accepted
time: 0ms
memory: 7708kb

input:

10 10
...***.*..
**...*.***
...***.*..
.**...*.*.
.*****..*.
..*.****.*
.**...****
..*..*.*.*
*.*.**....
....**...*

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 351ms
memory: 109772kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 343ms
memory: 110072kb

input:

3000 3000
...................................................................................................................*......................................................................................................................................................................*..........

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 311ms
memory: 109768kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 336ms
memory: 109712kb

input:

3000 3000
.........................................................................................................*...........................................................................................................................................................................................

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 325ms
memory: 109836kb

input:

3000 3000
......................................................................................................................................*........................................................................................................................................*.....................

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 331ms
memory: 109836kb

input:

3000 3000
...........................................*.........................................................................................................................................................................................................................................................

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 347ms
memory: 110036kb

input:

3000 3000
..............................*................................................................................................................*.....................................................................................................................................................

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 309ms
memory: 110028kb

input:

3000 3000
................................................................*....*................................................................................................................................................................................*..............................................

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 335ms
memory: 109728kb

input:

3000 3000
............................................................................................*.............................................................................*.....................................................................................................*....................

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 326ms
memory: 109872kb

input:

3000 3000
......................................*..........................................................................................................................................................*...................................................................................................

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 331ms
memory: 109776kb

input:

3000 3000
.................................................................................................................................................................................................................................*...................................................................

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 333ms
memory: 108632kb

input:

3000 3000
......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 276ms
memory: 104980kb

input:

3000 3000
..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 3ms
memory: 42888kb

input:

3000 3000
..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 13ms
memory: 42360kb

input:

3000 3000
.**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

score: 0
Accepted
time: 0ms
memory: 5620kb

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 0ms
memory: 7668kb

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 0ms
memory: 7732kb

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 0ms
memory: 42392kb

input:

3000 3000
.***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 18ms
memory: 39748kb

input:

3000 3000
*******************************************************************************************************************************************************************************************************************************************************.******************************************...

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 332ms
memory: 109772kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 331ms
memory: 109828kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 326ms
memory: 109832kb

input:

3000 3000
...**................................................................................................................................................................................................................................................................................................

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 324ms
memory: 109836kb

input:

3000 3000
...*.*...............................................................................................................................................................................................................................................................................................

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 349ms
memory: 110072kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 339ms
memory: 110072kb

input:

3000 3000
....**.*.............................................................................................................................................................................................................................................................................................

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 333ms
memory: 109996kb

input:

3000 3000
....****.............................................................................................................................................................................................................................................................................................

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 330ms
memory: 109776kb

input:

3000 3000
.........*...........................................................................................................................................................................................................................................................................................

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 329ms
memory: 109764kb

input:

3000 3000
.*.......*.............................................................................................................*................................................................................*............................................................................................

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 355ms
memory: 110072kb

input:

3000 3000
.**...........................*..........................................................................................................................................*...........................................................................................................................

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 314ms
memory: 109956kb

input:

3000 3000
....*................................................................................................................................................................................................................................................................................................

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 326ms
memory: 109776kb

input:

3000 3000
..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 332ms
memory: 109992kb

input:

3000 3000
......*.........*...................................................................................*.....................................................................................................................*................................................*.........................

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 340ms
memory: 109768kb

input:

3000 3000
....*.**....*................*............................*..........*...............................................................................................................................................................................................................................

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 323ms
memory: 109812kb

input:

3000 3000
...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 309ms
memory: 110060kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

score: 0
Accepted
time: 0ms
memory: 7812kb

input:

1 3000
........................................................................................................................................................................................................................................................................................................

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 339ms
memory: 109776kb

input:

3000 3000
.*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 335ms
memory: 110060kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35964327

result:

ok 1 number(s): "35964327"