QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276739#6739. Teleportucup-team958#AC ✓577ms116468kbC++141.4kb2023-12-06 10:13:332023-12-06 10:13:33

Judging History

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

  • [2023-12-06 10:13:33]
  • 评测
  • 测评结果:AC
  • 用时:577ms
  • 内存:116468kb
  • [2023-12-06 10:13:33]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
using namespace std;
const int maxn=5010;
struct pos{
	int x,y;
	pos(int a=0,int b=0){x=a,y=b;}
};
int p[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
queue<pos>q;
char a[maxn][maxn];
int f[maxn][maxn];
int n,k;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	memset(f,-1,sizeof(f));
	q.push(pos(1,1)),f[1][1]=0;
	while(!q.empty()){
		pos t=q.front(); q.pop();
		for(int i=1;i<=min(k/2,min(n-t.x,n-t.y));i++){
			pos M(t.x+i,t.y+i);
			if(~f[M.x][M.y]) break;
			if(a[M.x][M.y]!='*')
				f[M.x][M.y]=f[t.x][t.y]+1,q.push(M);
		}
		for(int i=0;i<=min((k-1)/2,min(n-t.y-1,n-t.x));i++){
			pos M(t.y+1+i,t.x+i);
			if(~f[M.x][M.y]) break;
			if(a[M.x][M.y]!='*')
				f[M.x][M.y]=f[t.x][t.y]+1,q.push(M);
		}for(int i=min(k/2,min(n-t.x,n-t.y));i;i--){
			pos M(t.x+i,t.y+i);
			if(~f[M.x][M.y]) break;
			if(a[M.x][M.y]!='*')
				f[M.x][M.y]=f[t.x][t.y]+1,q.push(M);
		}
		for(int i=min((k-1)/2,min(n-t.y-1,n-t.x));~i;i--){
			pos M(t.y+1+i,t.x+i);
			if(~f[M.x][M.y]) break;
			if(a[M.x][M.y]!='*')
				f[M.x][M.y]=f[t.x][t.y]+1,q.push(M);
		}
		for(int i=0;i<4;i++){
			pos M(t.x+p[i][0],t.y+p[i][1]);
			if(M.x<1||M.y<1||M.x>n||M.y>n) continue;
			if(a[M.x][M.y]=='*') continue;
			if(~f[M.x][M.y]) continue;
			f[M.x][M.y]=f[t.x][t.y]+1;
			q.push(M);
		}
	}
	printf("%d\n",f[n][n]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 103500kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 103632kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 44ms
memory: 106492kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: 0
Accepted
time: 58ms
memory: 106568kb

input:

975 434
.*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 56ms
memory: 106516kb

input:

966 19
..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....

output:

104

result:

ok 1 number(s): "104"

Test #6:

score: 0
Accepted
time: 55ms
memory: 106484kb

input:

973 199
..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 60ms
memory: 106556kb

input:

984 95
.....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....

output:

21

result:

ok 1 number(s): "21"

Test #8:

score: 0
Accepted
time: 346ms
memory: 116468kb

input:

2996 2
..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...

output:

3354

result:

ok 1 number(s): "3354"

Test #9:

score: 0
Accepted
time: 550ms
memory: 115988kb

input:

2905 1023
.........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 577ms
memory: 116312kb

input:

2978 104
.*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...

output:

58

result:

ok 1 number(s): "58"