제출 #1092002

#제출 시각아이디문제언어결과실행 시간메모리
1092002marText editor (CEOI24_editor)C++14
14 / 100
138 ms78928 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; int arr[n + 1]; long long int dp[n + 2][5002]; long long int vis[n + 2][5002]; for(int i = 1; i <= n; i++){ cin >> arr[i]; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= 5000; j++){ dp[i][j] = 1e9; vis[i][j] = 0; } } queue<pair<int,int>>q; q.push({x1,y1}); dp[x1][y1] = 0; vis[x1][y1]++; while(!q.empty()){ pair<int,int>v = q.front(); q.pop(); int x = v.first; int y = v.second; if(x == x2 and y == y2){ cout << dp[x][y]; return 0; } int nx,ny; if(y != (arr[x] + 1)){ nx = x; ny = y + 1; if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } }else{ if(x != n){ nx = x + 1; ny = 1; if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } } } if(y > 1){ nx = x; ny = y - 1; if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } }else{ if(x != 1){ nx = x - 1; ny = arr[x - 1] + 1; if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } } } if(x != 1){ nx = x - 1; ny = min(arr[x - 1] + 1, y); if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } } if(x != n){ nx = x + 1; ny = min(arr[x + 1] + 1, y); if(vis[nx][ny] == 0){ dp[nx][ny] = dp[x][y] +1; q.push({nx,ny}); vis[nx][ny]++; } } } // cout << endl; // cout << dp[2][1] << 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...