제출 #1068496

#제출 시각아이디문제언어결과실행 시간메모리
1068496vjudge1Text editor (CEOI24_editor)C++17
14 / 100
548 ms40712 KiB
#include <bits/stdc++.h> #define int long long using namespace std; void solve() { int n, sl, sc, el, ec; cin >> n >> sl >> sc >> el >> ec; int l[n+1]; for(int i=1; i<=n; ++i) { cin >> l[i]; ++l[i]; } priority_queue<pair<int,pair<int,int>>>pq; vector<vector<int>>dp(n+1, vector<int>(5005, INT_MAX)); vector<vector<bool>>visited(n+1, vector<bool>(5005, 0)); dp[sl][sc] = 0; pq.push({0, {sl, sc}}); while(!pq.empty()) { int x = pq.top().second.first, y = pq.top().second.second; if(x == el && y == ec) break; pq.pop(); if(visited[x][y]) continue; visited[x][y] = 1; if(x != n) { // down int new_y = y; new_y = min(new_y, l[x+1]); if(dp[x+1][new_y] > dp[x][y] + 1) { dp[x+1][new_y] = dp[x][y] + 1; pq.push({-dp[x+1][new_y], {x+1, new_y}}); } } if(x != 1) { // up int new_y = y; new_y = min(new_y, l[x-1]); if(dp[x-1][new_y] > dp[x][y] + 1) { dp[x-1][new_y] = dp[x][y] + 1; pq.push({-dp[x-1][new_y], {x-1, new_y}}); } } if(y == 1 && x != 1) { // left up int new_x = x - 1, new_y = l[new_x]; if(dp[x][y] + 1 < dp[new_x][new_y]) { dp[new_x][new_y] = dp[x][y] + 1; pq.push({-dp[new_x][new_y], {new_x, new_y}}); } } else if(y != 1) { // left if(dp[x][y] + 1 < dp[x][y-1]) { dp[x][y-1] = dp[x][y] + 1; pq.push({-dp[x][y-1], {x, y-1}}); } } if(y == l[x] && x != n) { // right down int new_x = x+1, new_y = 1; if(dp[x][y] + 1 < dp[new_x][new_y]) { dp[new_x][new_y] = dp[x][y] + 1; pq.push({-dp[new_x][new_y], {new_x, new_y}}); } } else if(y != l[x]) { // right if(dp[x][y] + 1 < dp[x][y+1]) { dp[x][y+1] = dp[x][y] + 1; pq.push({-dp[x][y+1], {x, y+1}}); } } } cout << dp[el][ec] << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while(t--) solve(); 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...