QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414837#6739. TeleportArnold_6RE 0ms0kbC++172.2kb2024-05-19 21:38:462024-05-19 21:38:48

Judging History

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

  • [2024-05-19 21:38:48]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-19 21:38:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n,k;
char mp[5005][5005];
int arr[15005];
bool v[5005][5005];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int main()
{
    freopen("111.txt","r",stdin);
    freopen("222.txt","w",stdout);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>mp[i]+1;
    }
    
    queue<pair<pair<int,int>,int> >q;
    q.push({{1,1},0});
    arr[n]=1;
    v[1][1]=1;

    while(q.size())
    {
        int x=q.front().first.first;
        int y=q.front().first.second;
        int step=q.front().second;
        q.pop();

        // cout<<"step="<<step<<" x="<<x<<" y="<<y<<endl;

        if(x==n && y==n)
        {
            cout<<step;
            // system("pause");
            return 0;
        }

        for(int i=0;i<4;i++)
        {
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<1 || nx>n || ny<1 || ny>n || v[nx][ny] || mp[nx][ny]=='*')continue;
            q.push({{nx,ny},step+1});
            v[nx][ny]=1;
            arr[n+nx-ny]=max(arr[n+nx-ny],ny);
        }

        int tx,ty,t;
        tx=x-y+arr[n+x-y];
        ty=arr[n+x-y];
        
        t=2*(tx-x);
        // cout<<"t="<<t<<" tx="<<tx<<" ty="<<ty<<endl;
        for(int i=2+t;i<=k;i+=2)
        {
            tx+=1;
            ty+=1;
            // cout<<"step="<<step<<" tx="<<tx<<" ty="<<ty<<endl;
            if(tx>n || ty>n)break;
            if(v[tx][ty] || mp[tx][ty]=='*')continue;
            
            v[tx][ty]=1;
            arr[n+tx-ty]=ty;
            q.push({{tx,ty},step+1});
        }

        tx=y+1-x+arr[n+y+1-x];
        ty=arr[n+y+1-x];
        t=1+2*(ty-x);
        if(tx>0&&ty>0&&!v[tx][ty])q.push({{tx,ty},step+1});

        for(int i=2+t;i<=k;i+=2)
        {
            tx+=1;
            ty+=1;
            // cout<<"step="<<step<<" tx="<<tx<<" ty="<<ty<<endl;
            if(tx>n || ty>n)break;
            if(v[tx][ty] || mp[tx][ty]=='*')continue;
            
            v[tx][ty]=1;
            arr[n+tx-ty]=ty;
            q.push({{tx,ty},step+1});
        }

    }
    cout<<-1;
    system("pause");
    fclose(stdin);
   
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3 2
.*.
.*.
...

output:


result: