QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276711 | #6739. Teleport | ucup-team958# | WA | 29ms | 107596kb | C++14 | 1.0kb | 2023-12-06 09:55:47 | 2023-12-06 09:55:48 |
Judging History
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*2<=k;i++){
pos M(t.x+i,t.y+i);
if(M.x>n||M.y>n||(~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*2+1<=k;i++){
pos M(t.y+1+i,t.x+i);
if(M.x>n||M.y>n||(~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: 10ms
memory: 103808kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 102876kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 29ms
memory: 107596kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
551
result:
wrong answer 1st numbers differ - expected: '540', found: '551'