Submission #1068689

# Submission time Handle Problem Language Result Execution time Memory
1068689 2024-08-21T11:23:05 Z vjudge1 Text editor (CEOI24_editor) C++17
0 / 100
1 ms 1116 KB
#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 > 0){
                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]++;
                }
            }
        
    }
    
    
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Runtime error 1 ms 1116 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Runtime error 1 ms 1116 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -