QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608947#833. Cells BlockingkgqyAC ✓351ms221408kbC++142.5kb2024-10-04 09:34:412024-10-04 09:34:43

Judging History

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

  • [2024-10-04 09:34:43]
  • 评测
  • 测评结果:AC
  • 用时:351ms
  • 内存:221408kb
  • [2024-10-04 09:34:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int w=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) w=w*10+ch-'0',ch=getchar();
	return w;
}
inline int gc(){
	char ch=getchar();
	while(ch!='*'&&ch!='.') ch=getchar();
	return ch=='*';
}
int n,m;
int blk[3005][3005],wtn;
int tob[3005][3005],toe[3005][3005];
pair<int,int> l1[6005],l2[6005];
int gre[3005][3005];
int blu[3005][3005],sblu=1;
main(){
	// freopen("in.in","r",stdin);
	// freopen("out1.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) blk[i][j]=gc(),wtn+=(blk[i][j]^1);
	tob[1][1]=blk[1][1]^1;
	for(int k=3;k<=n+m;k++){
		for(int i=1,j=k-1;j;i++,j--){
			if(i>n||j>m) continue;
			if(blk[i][j]) continue;
			tob[i][j]=tob[i-1][j]|tob[i][j-1];
		}
	}
	if(!tob[n][m]) return printf("%lld\n",max(0ll,wtn*(wtn-1)/2)),0;
	toe[n][m]=1;
	for(int k=n+m-1;k>=2;k--){
		for(int i=1,j=k-1;j;i++,j--){
			if(i>n||j>m) continue;
			if(blk[i][j]) continue;
			toe[i][j]=toe[i+1][j]|toe[i][j+1];
		}
	}
	// for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) putchar(toe[i][j]+'0');
	l1[1]={1,1};
	for(int i=2;i<n+m;i++){
		int lsx=l1[i-1].first,lsy=l1[i-1].second;
		if(toe[lsx+1][lsy]) lsx++;
		else lsy++;
		l1[i]={lsx,lsy};
		// printf("%d %d\n",lsx,lsy);
	}
	l2[1]={1,1};
	blu[1][1]=1;
	for(int i=2;i<n+m;i++){
		int lsx=l2[i-1].first,lsy=l2[i-1].second;
		if(toe[lsx][lsy+1]) lsy++;
		else lsx++;
		l2[i]={lsx,lsy};
		if(l1[i]==l2[i]) blu[lsx][lsy]=1,sblu++;//,printf("blu %d %d\n",lsx,lsy);
	}
	// for(int i=1;i<n+m;i++) printf("%d %d %d %d %d\n",i,l1[i].first,l1[i].second,l2[i].first,l2[i].second);
	int ans=sblu*(wtn-sblu)+sblu*(sblu-1)/2;
	// printf("%d\n",ans);
	for(int i=1;i<n+m;i++){
		int nx=l1[i].first,ny=l1[i].second;
		if(blu[nx][ny]) continue;
		// printf("%d %d %d\n",i,nx,ny);
		nx--,ny++;
		while(!tob[nx][ny]||!toe[nx][ny]) nx--,ny++;
		// printf("%d %d %d\n",i,nx,ny);
		if(l2[i].first==nx&&l2[i].second==ny&&!blu[nx][ny]) ans++;//,printf("%d %d\n",nx,ny);
		int tx=nx,ty=ny;
		for(int j=i-1;j;j--){
			if(tob[tx][ty-1]) ty--;
			else tx--;
			if(l2[j].first==tx&&l2[j].second==ty&&!blu[tx][ty]) ans++;//,printf("%d %d\n",tx,ty);
		}
		tx=nx,ty=ny;
		for(int j=i+1;j<n+m;j++){
			if(toe[tx+1][ty]) tx++;
			else ty++;
			// printf("JG %d %d\n",tx,ty);
			if(l2[j].first==tx&&l2[j].second==ty&&!blu[tx][ty]) ans++;//,printf("%d %d\n",tx,ty);
		}
	}
	printf("%lld\n",ans);
}
/*
5 5
.....
.*.*.
.....
.*...
..*..
*/

詳細信息

Test #1:

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

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 301ms
memory: 217588kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 311ms
memory: 217532kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 311ms
memory: 217480kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 327ms
memory: 217712kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 323ms
memory: 217528kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 324ms
memory: 217532kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 320ms
memory: 217520kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 317ms
memory: 217724kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 265ms
memory: 217584kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 332ms
memory: 217588kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 295ms
memory: 217508kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 322ms
memory: 217596kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 298ms
memory: 217724kb

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 98ms
memory: 145268kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 99ms
memory: 145212kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 107ms
memory: 146472kb

input:

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

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 43ms
memory: 105152kb

input:

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

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 337ms
memory: 217596kb

input:

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

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 344ms
memory: 217580kb

input:

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

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 315ms
memory: 217580kb

input:

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

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 302ms
memory: 217736kb

input:

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

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 336ms
memory: 217604kb

input:

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

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 328ms
memory: 217592kb

input:

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

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 299ms
memory: 217736kb

input:

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

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

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

input:

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

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 305ms
memory: 217588kb

input:

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

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 312ms
memory: 217668kb

input:

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

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 304ms
memory: 217592kb

input:

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

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 325ms
memory: 217524kb

input:

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

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 277ms
memory: 219524kb

input:

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

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 323ms
memory: 217596kb

input:

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

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 302ms
memory: 221408kb

input:

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

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 311ms
memory: 217660kb

input:

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

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

score: 0
Accepted
time: 10ms
memory: 9916kb

input:

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

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 351ms
memory: 217532kb

input:

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

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 291ms
memory: 217592kb

input:

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

output:

35964327

result:

ok 1 number(s): "35964327"