제출 #1300550

#제출 시각아이디문제언어결과실행 시간메모리
1300550iq500Text editor (CEOI24_editor)C++20
14 / 100
117 ms40284 KiB
#include <bits/stdc++.h> #define int long long #define fir first #define sec second using namespace std; int n; int sr, sc, er, ec; vector<vector<int>> a; vector<vector<bool>> v; queue<pair<int, int>> q; void bfs(){ q.push({sr, sc}); v[sr][sc]=1; a[sr][sc]=0; while(q.size()){ int x=q.front().fir, y=q.front().sec, d=a[x][y]+1; q.pop(); //yukarı if(x>1){ int nw=a[x-1].size()-1; if(nw+1<=y && !v[x-1][nw]){ v[x-1][nw]=1; a[x-1][nw]=d; q.push({x-1, nw}); } else if(nw+1>y && !v[x-1][y]){ v[x-1][y]=1; a[x-1][y]=d; q.push({x-1, y}); } } //aşağı if(x<n){ int nw=a[x+1].size()-1; if(nw+1<=y && !v[x+1][nw]){ v[x+1][nw]=1; a[x+1][nw]=d; q.push({x+1, nw}); } else if(nw+1>y && !v[x+1][y]){ v[x+1][y]=1; a[x+1][y]=d; q.push({x+1, y}); } } //sağa if(y<a[x].size()-1){ if(!v[x][y+1]){ v[x][y+1]=1; a[x][y+1]=d; q.push({x, y+1}); } } else{ //bir alt satıra geççez if(x<n && !v[x+1][1]){ v[x+1][1]=1; a[x+1][1]=d; q.push({x+1, 1}); } } //sola if(y>1){ if(!v[x][y-1]){ v[x][y-1]=1; a[x][y-1]=d; q.push({x, y-1}); } } else{ if(x>1 && !v[x-1][a[x-1].size()-1]){ v[x-1][a[x-1].size()-1]=1; a[x-1][a[x-1].size()-1]=d; q.push({x-1, a[x-1].size()-1}); } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; cin>>sr>>sc>>er>>ec; bool flag=true; //s-row, s-col, e-row, e-col a.resize(n+1); v.resize(n+1); for(int i=1; i<=n; i++){ int x; cin>>x; if(i!=1 && x+2!=a[i-1].size()) flag=false; a[i].resize(x+2); v[i].resize(x+2, 0); } if(!flag){ bfs(); cout<<a[er][ec]; } else{ int gh=sc+a[er].size()-1-ec+abs(er-sr); if(er<sr) gh--; else gh++; int b=abs(sr-er)+abs(sc-ec); int c=a[sr].size()-1-sc+ec+abs(sr-er); if(sr<er) c--; else c++; cout<<min(gh, min(b, c)); } 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...