QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592124#833. Cells BlockingSunsetGlow95AC ✓329ms118560kbC++142.2kb2024-09-26 20:51:052024-09-26 20:51:05

Judging History

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

  • [2024-09-26 20:51:05]
  • 评测
  • 测评结果:AC
  • 用时:329ms
  • 内存:118560kb
  • [2024-09-26 20:51:05]
  • 提交

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;
    }
  }
  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 (!mat[i][j]) {
        luc[i][j] = -1;
        continue;
      }
      if (j && ~luc[i][j - 1]) luc[i][j] = luc[i][j - 1] + (rc[i + j] == i);
      else if (i && ~luc[i - 1][j]) luc[i][j] = luc[i - 1][j] + (rc[i + j] == i);
      else luc[i][j] = -1;
    }
  }
  for (int x(0), y(0);;) {
    if (rc[x + y] == x) ++bp;
    else {
      int yy(y + 1);
      while (ln[x + y - yy][yy] == -1 || luc[x + y - yy][yy] == -1) ++yy;
      int xx(x + y - yy);
      ans += luc[xx][yy] + ldc[xx][yy] - (rc[x + y] == xx);
    }
    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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 12100kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 258ms
memory: 118484kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 255ms
memory: 118348kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 259ms
memory: 118556kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 250ms
memory: 118448kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 262ms
memory: 118444kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 258ms
memory: 118364kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 263ms
memory: 118416kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 249ms
memory: 118364kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 247ms
memory: 118448kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 259ms
memory: 118444kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 271ms
memory: 118552kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 297ms
memory: 118412kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

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

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 261ms
memory: 48208kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 289ms
memory: 48092kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 2ms
memory: 12028kb

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 262ms
memory: 49452kb

input:

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

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 233ms
memory: 49772kb

input:

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

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 261ms
memory: 118432kb

input:

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

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 260ms
memory: 118556kb

input:

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

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 267ms
memory: 118508kb

input:

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

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 251ms
memory: 118412kb

input:

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

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 273ms
memory: 118452kb

input:

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

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 242ms
memory: 118488kb

input:

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

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 249ms
memory: 118448kb

input:

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

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 256ms
memory: 118552kb

input:

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

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 269ms
memory: 118452kb

input:

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

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 258ms
memory: 118556kb

input:

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

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 259ms
memory: 118488kb

input:

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

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 256ms
memory: 118556kb

input:

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

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 255ms
memory: 118560kb

input:

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

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 263ms
memory: 118512kb

input:

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

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 264ms
memory: 118452kb

input:

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

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 245ms
memory: 118404kb

input:

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

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

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

input:

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

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 258ms
memory: 118448kb

input:

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

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 245ms
memory: 118552kb

input:

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

output:

35964327

result:

ok 1 number(s): "35964327"