QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185417 | #6739. Teleport | ucup-team134# | TL | 128ms | 59032kb | C++14 | 1.3kb | 2023-09-22 01:54:10 | 2023-09-22 01:54:11 |
Judging History
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;
if(x==n && y==n)break;
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});
}
}
auto it=can[x-y+N].lower_bound({x,y});
while(true){
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(it++);
}
it=can[y+1-x+N].lower_bound({y+1,x});
while(true){
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(it++);
}
}
printf("%i\n",dist[n][n]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6556kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8172kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 128ms
memory: 55808kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 102ms
memory: 58296kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 101ms
memory: 57812kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 94ms
memory: 58052kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 96ms
memory: 59032kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: -100
Time Limit Exceeded
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...