QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185414#6739. Teleportucup-team134#TL 213ms59804kbC++141.3kb2023-09-22 01:50:362023-09-22 01:50:38

Judging History

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

  • [2023-09-22 01:50:38]
  • 评测
  • 测评结果:TL
  • 用时:213ms
  • 内存:59804kb
  • [2023-09-22 01:50:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=5050;
char s[N][N];
int dist[N][N];
set<pair<int,int>> can[2*N];
int mv[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int main(){
	int n,k;
	scanf("%i %i",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dist[i][j]=-1;
			if(s[i][j]!='*' && (i!=1 || j!=1)){
				can[i-j+N].insert({i,j});
			}
		}
	}
	dist[1][1]=0;
	queue<pair<int,int>> q;
	q.push({1,1});
	while(q.size()){
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){
			int nx=x+mv[i][0];
			int ny=y+mv[i][1];
			if(s[nx][ny]!='.')continue;
			if(dist[nx][ny]==-1){
				dist[nx][ny]=dist[x][y]+1;
				q.push({nx,ny});
				can[nx-ny+N].erase({nx,ny});
			}
		}
		while(true){
			auto it=can[x-y+N].lower_bound({x,y});
			if(it==can[x-y+N].end())break;
			int nx=it->first;
			int ny=it->second;
			if(x+y+k<nx+ny)break;
			dist[nx][ny]=dist[x][y]+1;
			q.push({nx,ny});
			can[nx-ny+N].erase({nx,ny});
		}
		while(true){
			auto it=can[y+1-x+N].lower_bound({y+1,x});
			if(it==can[y+1-x+N].end())break;
			int nx=it->first;
			int ny=it->second;
			if(x+y+k<nx+ny)break;
			dist[nx][ny]=dist[x][y]+1;
			q.push({nx,ny});
			can[nx-ny+N].erase({nx,ny});
		}
	}
	printf("%i\n",dist[n][n]);
	return 0;
}

詳細信息

Test #1:

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

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 199ms
memory: 57724kb

input:

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

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: 0
Accepted
time: 197ms
memory: 59804kb

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 189ms
memory: 57508kb

input:

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

output:

104

result:

ok 1 number(s): "104"

Test #6:

score: 0
Accepted
time: 190ms
memory: 59452kb

input:

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

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

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

output:

21

result:

ok 1 number(s): "21"

Test #8:

score: -100
Time Limit Exceeded

input:

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

output:


result: