QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227925#6739. TeleportwangqingxianRE 1ms3436kbC++141.4kb2023-10-28 09:23:552023-10-28 09:23:55

Judging History

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

  • [2023-10-28 09:23:55]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3436kb
  • [2023-10-28 09:23:55]
  • 提交

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<<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 2
.*.
.*.
...
 
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Runtime Error

input:

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

output:


result: