QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327969 | #833. Cells Blocking | OctoberEstuary | WA | 224ms | 115940kb | C++14 | 2.1kb | 2024-02-15 15:46:26 | 2024-02-15 15:46:50 |
Judging History
answer
#include<bits/stdc++.h>
#define Maxn 6003
#define LL long long
using namespace std;
int n,m;
LL white,ans,sam;
char s[Maxn][Maxn];
int f[Maxn][Maxn],g[Maxn][Maxn];
int lx[Maxn],ly[Maxn],rx[Maxn],ry[Maxn],tx[Maxn],ty[Maxn],tot;
void pre(){
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++){
scanf("%s",s[i]+1);
for(int j=1; j<=m; j++){
white += (s[i][j] == '.');
}
}
f[n][m] = 1;
for(int i=n; i>=1; i--){
for(int j=m; j>=1; j--){
if(i<n && f[i+1][j]){ f[i][j] = 1; }
if(j<m && f[i][j+1]){ f[i][j] = 1; }
if(s[i][j] == '*'){ f[i][j] = 0; }
}
}
g[1][1] = 1;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(i>1 && g[i-1][j]){ g[i][j] = 1; }
if(j>1 && g[i][j-1]){ g[i][j] = 1; }
if(s[i][j] == '*'){ g[i][j] = 0; }
}
}
}
void qry_left(){
//left_most
int x=1, y=1;
lx[1] = ly[1] = tot = 1;
while(x!=n || y!=m){
(x<n && f[x+1][y]) ? (x++) : (y++);
tot++;
lx[tot] = x; ly[tot] = y;
}
}
void qry_right(){
//right_most
int x=1, y=1;
rx[1] = ry[1] = tot = 1;
while(x!=n || y!=m){
(y<m && f[x][y+1]) ? (y++) : (x++);
tot++;
rx[tot] = x; ry[tot] = y;
}
}
LL qry_sam(int ax[], int ay[], int bx[], int by[]){
LL ret=0;
for(int i=1; i<=tot; i++)if(ax[i]==bx[i] && ay[i]==by[i]){
ret++;
}
return ret;
}
void bld(int x, int y){
//left_most
int u, v, cur=x+y-1;
tx[cur]=x; ty[cur]=y;
// build Left_Up
u = x; v = y;
for(int i=cur-1; i>=1; i--){
(v>1 && g[u][v-1]) ? (v--) : (u--);
tx[i] = u; ty[i] = v;
}
// build Down_Right
u = x; v = y;
for(int i=cur+1; i<=tot; i++){
(u<n && g[u+1][v]) ? (u++) : (v++);
tx[i] = u; ty[i] = v;
}
}
void work1(){
sam = qry_sam(lx, ly, rx, ry);
ans = sam*(white-1) - sam*(sam-1)/2;
}
void work2(){
int x,y;
for(int i=1; i<=tot; i++)if(lx[i]!=rx[i] || ly[i]!=ry[i]){
x = lx[i]-1; y = ly[i]+1;
while(!f[x][y] || !g[x][y]){
x--;
y++;
}
bld(x, y);
ans += qry_sam(tx, ty, rx, ry)-sam;
}
}
int main(){
pre();
if(!f[1][1]){
printf("%lld\n", white*(white-1)/2);
return 0;
}
qry_left();
qry_right();
work1();
work2();
printf("%lld", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4008kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4008kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 78ms
memory: 115720kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 129ms
memory: 115676kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 124ms
memory: 115812kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 138ms
memory: 115748kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 152ms
memory: 115720kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 154ms
memory: 115744kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 158ms
memory: 115652kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 168ms
memory: 115652kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 181ms
memory: 115728kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 152ms
memory: 115412kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 159ms
memory: 115288kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 206ms
memory: 115532kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 224ms
memory: 115676kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 95ms
memory: 115648kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 103ms
memory: 115564kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 107ms
memory: 115760kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 34ms
memory: 115676kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 167ms
memory: 115940kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 147ms
memory: 115872kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 89ms
memory: 115696kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 67ms
memory: 115732kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 162ms
memory: 115824kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 157ms
memory: 115388kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 166ms
memory: 115520kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 171ms
memory: 115700kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 187ms
memory: 115620kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 154ms
memory: 115656kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 164ms
memory: 115672kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 166ms
memory: 115732kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 175ms
memory: 115640kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 138ms
memory: 115640kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 160ms
memory: 115536kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 170ms
memory: 115564kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: -100
Wrong Answer
time: 157ms
memory: 115408kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979544
result:
wrong answer 1st numbers differ - expected: '88979547', found: '88979544'