QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185413#6739. Teleportucup-team134#WA 193ms57736kbC++141.3kb2023-09-22 01:49:292023-09-22 01:49:29

Judging History

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

  • [2023-09-22 01:49:29]
  • 评测
  • 测评结果:WA
  • 用时:193ms
  • 内存:57736kb
  • [2023-09-22 01:49:29]
  • 提交

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(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: 6296kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 193ms
memory: 57736kb

input:

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

output:

534

result:

wrong answer 1st numbers differ - expected: '540', found: '534'