Submission #287538

# Submission time Handle Problem Language Result Execution time Memory
287538 2020-08-31T19:29:09 Z eagle30 Awesome Arrowland Adventure (eJOI19_adventure) C++14
0 / 100
2000 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
char arr[1000][1000];
long long n, m;
int dist(char a, char b){
    if(a=='N'){
        if(b=='N')
            return 0;
        else if(b=='E')
            return 1;
        else if(b=='S')
            return 2;
        else
            return 3;
    }
    else if(a=='E'){
        if(b=='N')
            return 3;
        else if(b=='E')
            return 0;
        else if(b=='S')
            return 1;
        else
            return 2;
    }
    else if(a=='S'){
        if(b=='N')
            return 2;
        else if(b=='E')
            return 3;
        else if(b=='S')
            return 0;
        else
            return 1;
    }
    else{
        if(b=='N')
            return 1;
        else if(b=='E')
            return 2;
        else if(b=='S')
            return 3;
        else
            return 0;
    }
}
long long recursive(long long hi1, long long hi2, long long yo){
    if(hi1<0 || hi1>=n || hi2<0 || hi2>=m)
        return 1000000000;
    if(hi1==n-1 && hi2==m-1)
        return 0;
    if(arr[hi1][hi2]=='X' || yo==0)
        return 1000000000;
    long long mini=2e9;
    char asdf=arr[hi1][hi2];
    mini=min(mini, recursive(hi1+1, hi2, yo-1)+dist(asdf, 'S'));
    mini=min(mini, recursive(hi1-1, hi2, yo-1)+dist(asdf, 'N'));
    mini=min(mini, recursive(hi1, hi2+1, yo-1)+dist(asdf, 'E'));
    mini=min(mini, recursive(hi1, hi2-1, yo-1)+dist(asdf, 'W'));
    return mini;
}
int main(){
cin>>n>>m;
for(long long i=0; i<n; i++){
    for(long long j=0; j<m; j++){
        cin>>arr[i][j];
    }
}
cout<<recursive(0, 0, n*m);
return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -