QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335559#833. Cells BlockingAFewSunsRE 120ms190252kbC++142.8kb2024-02-23 16:11:122024-02-23 16:11:13

Judging History

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

  • [2024-02-23 16:11:13]
  • 评测
  • 测评结果:RE
  • 用时:120ms
  • 内存:190252kb
  • [2024-02-23 16:11:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll n,m,f[3030][3030],g[3030][3030],ans=0;
bl ck1[3030][3030],ck2[3030][3030],pd1[3030][3030],pd2[3030][3030];
char s[3030][3030];
int main(){
	n=read();
	m=read();
	fr(i,1,n) scanf("%s",s[i]+1);
	if(s[1][1]=='*'||s[n][m]=='*'){
		ll all0=0;
		fr(i,1,n) fr(j,1,m) all0+=(s[i][j]=='.');
		write(all0*(all0-1)/2);
		return 0;
	}
	ck1[1][1]=1;
	fr(i,1,n){
		fr(j,1,m){
			ck1[i][j]|=ck1[i-1][j]|ck1[i][j-1];
			if(s[i][j]=='*') ck1[i][j]=0;
		}
	}
	ck2[n][m]=1;
	pfr(i,n,1){
		pfr(j,m,1){
			ck2[i][j]|=ck2[i+1][j]|ck2[i][j+1];
			if(s[i][j]=='*') ck2[i][j]=0;
		}
	}
	ll x=1,y=1;
	pd1[1][1]=pd2[1][1]=1;
	while(x<n||y<m){
		if(ck2[x+1][y]) x++;
		else y++;
		pd1[x][y]=1;
	}
	x=y=1;
	while(x<n||y<m){
		if(ck2[x][y+1]) y++;
		else x++;
		pd2[x][y]=1;
	}
	ll all0=0,all=0;
	fr(i,1,n) fr(j,1,m) if(s[i][j]=='.') all0++;
	fr(i,1,n) fr(j,1,m) if(pd1[i][j]&&pd2[i][j]) all++;
	ans=all*(all0-all)+all*(all-1)/2;
	fr(i,1,n){
		fr(j,1,m){
			if(ck1[i][j-1]) f[i][j]=f[i][j-1]+(pd2[i][j]&&!pd1[i][j]);
			else if(ck1[i-1][j]) f[i][j]=f[i-1][j]+(pd2[i][j]&&!pd1[i][j]);
		}
	}
	pfr(i,n,1){
		pfr(j,m,1){
			if(ck2[i+1][j]) g[i][j]=g[i+1][j]+(pd2[i][j]&&!pd1[i][j]);
			else if(ck2[i][j+1]) g[i][j]=g[i][j+1]+(pd2[i][j]&&!pd1[i][j]);
		}
	}
	fr(i,1,n){
		fr(j,1,m){
			if(!pd1[i][j]) continue;
			if(pd2[i][j]) continue;
			x=i-1;
			y=j+1;
			while(!ck1[x][y]||!ck2[x][y]){
				x--;
				y++;
			}
			ans+=f[x][y]+g[x][y]-(pd2[x][y]&&!pd1[x][y]);
		}
	}
	write(ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3796kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 90ms
memory: 190252kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 83ms
memory: 190168kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 50ms
memory: 190028kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 66ms
memory: 189892kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 86ms
memory: 189856kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 65ms
memory: 189940kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 73ms
memory: 189756kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

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

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 53ms
memory: 189584kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 65ms
memory: 189828kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 75ms
memory: 189564kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 83ms
memory: 183712kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 120ms
memory: 163596kb

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: -100
Runtime Error

input:

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

output:


result: