QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331592#833. Cells BlockingJWRuixiAC ✓192ms83344kbC++172.2kb2024-02-18 15:37:332024-02-18 15:37:34

Judging History

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

  • [2024-02-18 15:37:34]
  • 评测
  • 测评结果:AC
  • 用时:192ms
  • 内存:83344kb
  • [2024-02-18 15:37:33]
  • 提交

answer

#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
using namespace std;

constexpr int N = 3e3 + 9;
int n, m, f[N][N], g[N][N];
char s[N][N];

struct P {
  int x, y;

  bool operator == (const P &rhs) const {
    return x == rhs.x && y == rhs.y;
  }
} u[N * 2], v[N * 2], q[N * 2];

int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  L (i, 1, n) cin >> (s[i] + 1);
  f[0][1] = g[n + 1][m] = 1;
  L (i, 1, n) {
    L (j, 1, m) {
      if (s[i][j] == '*') {
        continue;
      }
      f[i][j] |= f[i - 1][j] | f[i][j - 1];
    }
  }
  R (i, n, 1) {
    R (j, m, 1) {
      if (s[i][j] == '*') {
        continue;
      }
      g[i][j] |= g[i + 1][j] | g[i][j + 1];
    }
  }
  int all = 0;
  L (i, 1, n) {
    all += count(s[i] + 1, s[i] + m + 1, '.');
  }
  if (!f[n][m]) {
    cout << (LL)all * (all - 1) / 2 << '\n';
    return 0;
  }
  int x = 1, y = 1;
  L (i, 1, n + m - 1) {
    u[i] = {x, y};
    if (g[x + 1][y]) {
      ++x;
    } else {
      ++y;
    }
  }
  x = n, y = m;
  R (i, n + m - 1, 1) {
    v[i] = {x, y};
    if (f[x - 1][y]) {
      --x;
    } else {
      --y;
    }
  }
  int eq = 0;
  L (i, 1, n + m - 1) {
    if (u[i] == v[i]) {
      ++eq;
    }
  }
  LL as = (LL)eq * (all - 1) - (LL)eq * (eq - 1) / 2;
  L (i, 1, n + m - 1) {
    if (u[i] == v[i]) {
      continue;
    }
    int x = u[i].x, y = u[i].y;
    R (t, x - 1, 1) {
      if (f[t][x + y - t] && g[t][x + y - t]) {
        y += x - t;
        x = t;
        break;
      }
    }
    q[x + y - 1] = {x, y};
    int r = x, c = y;
    L (j, x + y, n + m - 1) {
      if (g[r + 1][c]) {
        ++r;
      } else {
        ++c;
      }
      q[j] = {r, c};
    }
    r = x, c = y;
    R (j, x + y - 2, 1) {
      if (f[r][c - 1]) {
        --c;
      } else {
        --r;
      }
      q[j] = {r, c};
    }
    L (j, 1, n + m - 1) {
      as += q[j] == v[j] && !(u[j] == v[j]);
    }
  }
  cout << as << '\n';
}
// I love WHQ!

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 167ms
memory: 83276kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 180ms
memory: 83332kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 184ms
memory: 83228kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 175ms
memory: 83336kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 182ms
memory: 83216kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 163ms
memory: 83196kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 183ms
memory: 83252kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 159ms
memory: 83336kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 171ms
memory: 83212kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 172ms
memory: 83228kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 159ms
memory: 83256kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 170ms
memory: 83228kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 171ms
memory: 83192kb

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 76ms
memory: 83124kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 66ms
memory: 83052kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 76ms
memory: 83112kb

input:

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

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 30ms
memory: 58864kb

input:

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

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 154ms
memory: 83220kb

input:

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

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 168ms
memory: 83280kb

input:

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

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 172ms
memory: 83212kb

input:

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

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 192ms
memory: 83252kb

input:

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

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 185ms
memory: 83252kb

input:

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

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 159ms
memory: 83196kb

input:

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

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 177ms
memory: 83216kb

input:

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

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 179ms
memory: 83252kb

input:

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

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 169ms
memory: 83272kb

input:

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

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 169ms
memory: 83324kb

input:

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

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 171ms
memory: 83272kb

input:

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

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 173ms
memory: 83272kb

input:

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

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 174ms
memory: 83220kb

input:

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

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 176ms
memory: 83268kb

input:

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

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 161ms
memory: 83216kb

input:

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

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 183ms
memory: 83280kb

input:

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

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

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

input:

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

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 168ms
memory: 83344kb

input:

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

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 184ms
memory: 83268kb

input:

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

output:

35964327

result:

ok 1 number(s): "35964327"