QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328051#833. Cells BlockingOctoberEstuaryAC ✓213ms115948kbC++142.2kb2024-02-15 16:34:022024-02-15 16:34:03

Judging History

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

  • [2024-02-15 16:34:03]
  • 评测
  • 测评结果:AC
  • 用时:213ms
  • 内存:115948kb
  • [2024-02-15 16:34:02]
  • 提交

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 && f[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;
//		cerr<<i<<" "<<ans<<"\n";
	}
}
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: 0ms
memory: 3808kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

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: 0ms
memory: 3924kb

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 87ms
memory: 115724kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 130ms
memory: 115856kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 149ms
memory: 115804kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 157ms
memory: 115720kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 152ms
memory: 115660kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 141ms
memory: 115752kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 143ms
memory: 115788kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 157ms
memory: 115488kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

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

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 155ms
memory: 115548kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 191ms
memory: 115288kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 191ms
memory: 115784kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 213ms
memory: 115576kb

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 105ms
memory: 115620kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 101ms
memory: 115600kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 115ms
memory: 115604kb

input:

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

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 34ms
memory: 115768kb

input:

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

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 143ms
memory: 115688kb

input:

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

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 155ms
memory: 115936kb

input:

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

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 92ms
memory: 115948kb

input:

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

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

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

input:

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

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 152ms
memory: 115904kb

input:

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

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 146ms
memory: 115552kb

input:

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

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 155ms
memory: 115536kb

input:

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

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 151ms
memory: 115788kb

input:

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

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 150ms
memory: 115652kb

input:

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

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

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

input:

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

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

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

input:

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

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

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

input:

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

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 164ms
memory: 115568kb

input:

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

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

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

input:

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

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 160ms
memory: 115692kb

input:

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

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

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

input:

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

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

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

input:

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

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 164ms
memory: 115692kb

input:

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

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

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

input:

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

output:

35964327

result:

ok 1 number(s): "35964327"