Submission #1188111

#TimeUsernameProblemLanguageResultExecution timeMemory
1188111user736482Maze (JOI23_ho_t3)C++20
0 / 100
709 ms916744 KiB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000009
#define INF 1000000019
#define INFL 1000000000000000099LL
#define POT (1<<20)
ll a,b,r,c,d,t,n,m,l,q,k,ak,ans,s;
vector<ll>g[13000000],g2[13000000],g3[13000000];
bool co[13000000];
ll dst[13000000];
bool odw[13000000];
ll in(){
    ll x=0;
    char ch=getchar_unlocked();
    while(ch>'9' || ch<'0')ch=getchar_unlocked();
    while(ch>='0' && ch<='9'){
        x*=10;
        x+=ch-'0';
        ch=getchar_unlocked();
    }
    return x;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    c=in();r=in();n=in();
    b=in();a=in();
    a--;b--;
    s=r*b+a;
    b=in();a=in();
    a--;b--;
    t=r*b+a;
    for(ll i=0;i<r*c;i++){
        char ch;
        ch=getchar_unlocked();
        while(ch!='.' && ch!='#')ch=getchar_unlocked();
        co[i+r+c]=(ch=='.');
    }
    for(ll i=r+c;i<r+c+r*c;i++){
       // if(i>=r){
            if(co[i])
            g[i].pb(i-r);
            g2[i].pb(i-r);
      //  }
      //  if(i+r<r*c){
            if(co[i])
            g[i].pb(i+r);
            g2[i].pb(i+r);
        //}
        if(i%r<r-1){
            if(co[i])
            g[i].pb(i+1);
            g2[i].pb(i+1);
        }
        if(i%r){
            if(co[i])
            g[i].pb(i-1);
            g2[i].pb(i-1);
        }
        swap(g3[i],g2[i]);
        if(i%r){
            g2[i].pb(i-r-1);
        }
        if(i%r<r-1){
            g2[i].pb(i-r+1);
        }
        if(i%r){
            g2[i].pb(i+r-1);
        }
        if(i%r<r-1){
            g2[i].pb(i+r+1);
        }
    }
    deque<pair<ll,ll>>pq;
    pq.pb({0,s+r+c});
    while(pq.size()){
        auto pom=pq.front();
        pq.pop_front();
        if(odw[pom.ss])continue;
        odw[pom.ss]=1;
        dst[pom.ss]=pom.ff;
        if(pom.ff%n!=n-1){
            for(ll i : g2[pom.ss]){
                pq.pb({pom.ff+1,i});
            }
        }

            for(ll i : g3[pom.ss]){
            pq.pb({pom.ff+1,i});
        
        }
        if(pom.ff%n==0){
            for(ll i : g[pom.ss]){
                pq.push_front({pom.ff,i});
            }
        }
    }
    cout<<(dst[t+r+c]+n-1)/n;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...