QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331589#833. Cells BlockingJWRuixiWA 182ms83284kbC++172.1kb2024-02-18 15:36:012024-02-18 15:36:01

Judging History

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

  • [2024-02-18 15:36:01]
  • 评测
  • 测评结果:WA
  • 用时:182ms
  • 内存:83284kb
  • [2024-02-18 15:36:01]
  • 提交

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[1][1] = g[n][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: 7828kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

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

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

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

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

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

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

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

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

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

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

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

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 166ms
memory: 83200kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

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

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

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

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

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

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 165ms
memory: 83240kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

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

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

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

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 61ms
memory: 83048kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 78ms
memory: 83048kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

score: -100
Wrong Answer
time: 1ms
memory: 7668kb

input:

1 1
*

output:

-1

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'