Submission #1272508

#TimeUsernameProblemLanguageResultExecution timeMemory
1272508meisgoodMaze (JOI23_ho_t3)C++20
0 / 100
2100 ms166876 KiB
#include <bits/stdc++.h> using namespace std ; string A[3003] ; vector <vector<vector<pair<int,int>>>> dist ; priority_queue <tuple<pair<int,int>,int,int,int>,vector<tuple<pair<int,int>,int,int,int>>,greater<tuple<pair<int,int>,int,int,int>>> q ; void pushh(pair<int,int> dd,int x,int y,int z){ if (dd<dist[x][y][z]) q.push({dd,x,y,z}) ; } int main(){ int N,M,K,i,j ; cin >> N >> M >> K ; int s1,s2,g1,g2 ; cin >> s1 >> s2 >> g1 >> g2 ; for (i = 1 ; i <= N ; i ++) cin >> A[i],A[i]='0'+A[i] ; dist=vector<vector<vector<pair<int,int>>>>(N+3,vector<vector<pair<int,int>>>(M+3,vector<pair<int,int>>(3,{INT_MAX,INT_MAX}))) ; q.push({{0,0},s1,s2,0}) ; while (!q.empty()){ auto [dd,x,y,z]=q.top() ; auto [d1,d2]=dd ; q.pop() ; if (dd>=dist[x][y][z]) continue ; dist[x][y][z]=dd ; // cout << x << " " << y << " " << x << " " << d1 << " " << d2 << endl ; if (z==0){ pushh({d1+1,0},x,y,2) ; } if (z==2){ pushh({d1,0},x,y,1) ; } if (z==1){ pushh({d1,0},x,y,0) ; pushh({d1+1,0},x,y,2) ; } if (z==0&&A[x][y]=='#') continue ; if (z==2&&d2+1<=K-1){ if (x+1<=N) pushh({d1,d2+1},x+1,y,z) ; if (x-1>=1) pushh({d1,d2+1},x-1,y,z) ; } if (z==2&&d2+1>=K){ if (x+1<=N) pushh({d1+1,0},x+1,y,z) ; if (x-1>=1) pushh({d1+1,0},x-1,y,z) ; } if (z==1&&d2+1<=K-1){ if (y+1<=M) pushh({d1,d2+1},x,y+1,z) ; if (y-1>=1) pushh({d1,d2+1},x,y-1,z) ; } if (z==1&&d2+1>=K){ if (y+1<=M) pushh({d1+1,0},x,y+1,z) ; if (y-1>=1) pushh({d1+1,0},x,y-1,z) ; } if (z==0){ if (x+1<=N) pushh({d1,0},x+1,y,z) ; if (x-1>=1) pushh({d1,0},x-1,y,z) ; if (y+1<=M) pushh({d1,0},x,y+1,z) ; if (y-1>=1) pushh({d1,0},x,y-1,z) ; } else { if (x+1<=N&&A[x+1][y]=='.') pushh({d1,0},x+1,y,z) ; if (x-1>=1&&A[x-1][y]=='.') pushh({d1,0},x-1,y,z) ; if (y+1<=M&&A[x][y+1]=='.') pushh({d1,0},x,y+1,z) ; if (y-1>=1&&A[x][y-1]=='.') pushh({d1,0},x,y-1,z) ; } } cout << dist[g1][g2][0].first << endl ; 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...