QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227923 | #6739. Teleport | wangqingxian | WA | 0ms | 3604kb | C++14 | 1.4kb | 2023-10-28 09:23:11 | 2023-10-28 09:23:11 |
Judging History
answer
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<queue>
#include<iomanip>
#include<stdlib.h>
#include<set>
#include<cmath>
#define lowbit(i) (i&-i)
using namespace std;
const int N=2e2+10,inf=0x7fffffff,mod=1e9+7;
int n,k;
struct giao{
int x;
int y;
int step;
};
queue<giao> que;
bool book[N][N];
int nx[4]={0,0,1,-1};
int ny[4]={1,-1,0,0};
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){
char ch;cin>>ch;
if(ch=='*') book[i][j]=1;
}
que.push({1,1,0});
book[1][1]=1;
while(!que.empty()){
giao hd=que.front();
que.pop();
if(hd.x==n&&hd.y==n){
cout<<hd.step+1<<endl;
return 0;
}
for(int i=0;i<4;i++){
int tx=hd.x+nx[i],ty=hd.y+ny[i];
if(tx<1||ty<1||tx>n||ty>n) continue;
if(book[tx][ty]) continue;
book[tx][ty]=1;
que.push({tx,ty,hd.step+1});
}
int lx=hd.x,ly=hd.y;
for(int i=1;i<=k;i++){
int tx=ly+1,ty=lx;
lx=tx;ly=ty;
if(tx<1||ty<1||tx>n||ty>n) break;
if(book[tx][ty]) continue;
book[tx][ty]=1;
que.push({tx,ty,hd.step+1});
}
}
cout<<-1<<endl;
return 0;
}
/*
3 3
.*.
.*.
...
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3604kb
input:
3 2 .*. .*. ...
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'