Submission #465096

# Submission time Handle Problem Language Result Execution time Memory
465096 2021-08-15T07:47:21 Z oscar1f Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
83 ms 8448 KB
#include<bits/stdc++.h>
using namespace std; 

const int MAX_TAILLE=500;
int nbLig,nbCol,dist,longueur,lig,col,direc;
int grille[MAX_TAILLE][MAX_TAILLE],dv[MAX_TAILLE][MAX_TAILLE][4];
deque<tuple<int,int,int>> aTraiter;
tuple<int,int,int> temp;
char carac;

int main() {
   ios_base::sync_with_stdio(false);
   cin>>nbLig>>nbCol;
   for (int i=0;i<nbLig;i++) {
      for (int j=0;j<nbCol;j++) {
         cin>>carac;
         if (carac=='X') {
            grille[i][j]=-1;
         }
         if (carac=='N') {
            grille[i][j]=0;
         }
         if (carac=='E') {
            grille[i][j]=1;
         }
         if (carac=='S') {
            grille[i][j]=2;
         }
         if (carac=='W') {
            grille[i][j]=3;
         }
      }
   }
   aTraiter.push_back(make_tuple(0,0,grille[0][0]));
   while (aTraiter.size()>0) {
      longueur=aTraiter.size();
      for (int i=0;i<longueur;i++) {
         temp=aTraiter.front();
         aTraiter.pop_front();
         lig=get<0>(temp);
         col=get<1>(temp);
         direc=get<2>(temp);
         if (lig==nbLig-1 and col==nbCol-1) {
            cout<<dist<<endl;
            return 0;
         }
         if (lig>=0 and lig<nbLig and col>=0 and col<nbCol and grille[lig][col]!=-1 and dv[lig][col][direc]==0) {
            dv[lig][col][direc]=1;
            aTraiter.push_back(make_tuple(lig,col,(direc+1)%4));
            longueur++;
            if (direc==0) {
               aTraiter.push_front(make_tuple(lig-1,col,grille[lig-1][col]));
            }
            if (direc==1) {
               aTraiter.push_front(make_tuple(lig,col+1,grille[lig][col+1]));
            }
            if (direc==2) {
               aTraiter.push_front(make_tuple(lig+1,col,grille[lig+1][col]));
            }
            if (direc==3) {
               aTraiter.push_front(make_tuple(lig,col-1,grille[lig][col-1]));
            }
         }
      }
      dist++;
   }
   cout<<-1<<endl;
   return 0;
}
   
   
     
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 16 ms 844 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 6 ms 1356 KB Output is correct
38 Correct 7 ms 892 KB Output is correct
39 Correct 50 ms 5476 KB Output is correct
40 Correct 83 ms 5448 KB Output is correct
41 Correct 29 ms 1480 KB Output is correct
42 Correct 52 ms 5468 KB Output is correct
43 Correct 17 ms 8448 KB Output is correct
44 Correct 11 ms 1484 KB Output is correct