#include <bits/stdc++.h>
using namespace std;
const int MAX_ELEMENTS = 500*500;
char laby[500][500];
struct Coords {
int lig, col;
};
bool cond =false;
Coords cases[9][MAX_ELEMENTS];
Coords decal[4] = {{0, 1}, {1, 0}, {0, -1},{-1, 0}};
int nbLigs, nbCols;
bool dans(int lig, int col) {
if (lig<0||col<0||col>=nbCols||lig>=nbLigs) return false;
else return true;
}
// int A
int nbCases[9];
void ajouter(int distance, int lig, int col) {
int pos = nbCases[distance];
cases[distance][pos].lig = lig;
cases[distance][pos].col = col;
nbCases[distance] ++;
}
int PPC() {
int curDist = 0;
int curCase;
ajouter(0, 0, 0);
while (true) {
if (curDist > 500*500) return -1;
nbCases[(curDist+9)%10] = 0;
for (curCase = 0; curCase < nbCases[(curDist)%10]; curCase ++) {
int curLig = cases[curDist%10][curCase].lig;
int curCol = cases[curDist%10][curCase].col;
// printf("%d %d\n",curLig, curCol);
if ((curCol == nbCols-1) && (curLig == nbLigs-1)){
return curDist;
}
if (laby[curLig][curCol] == 'X') continue;
int curPos;
if (laby[curLig][curCol] == 'E') curPos = 0;
if (laby[curLig][curCol] == 'S') curPos = 1;
if (laby[curLig][curCol] == 'W') curPos = 2;
if (laby[curLig][curCol] == 'N') curPos = 3;
int adjDist = 0;
for (int dir = 0; dir < 4; dir ++) {
int ligAdj = curLig + decal[curPos].lig;
int colAdj = curCol + decal[curPos].col;
if (dans(ligAdj, colAdj) && ((laby[ligAdj][colAdj] != 'X') || ((ligAdj == nbLigs-1) && (colAdj == nbCols-1)))) {
ajouter((adjDist+curDist)%10, ligAdj, colAdj);
// if ((curLig == 1) && (curCol == 1))
// printf("%d %d %d\n", ligAdj, colAdj, adjDist);
}
curPos ++;
curPos = curPos%4;
adjDist ++;
}
laby[curLig][curCol] = 'X';
}
curDist ++;
}
}
int main() {
cin >> nbLigs >> nbCols;
for (int iLig = 0; iLig < nbLigs; iLig ++) {
string S; cin >> S;
for (int iCol = 0; iCol < nbCols; iCol ++) {
laby[iLig][iCol] = S[iCol];
}
}
printf("%d\n", PPC());
}
Compilation message
adventure.cpp: In function 'int PPC()':
adventure.cpp:58:16: warning: 'curPos' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | curPos ++;
| ~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
308 KB |
Output is correct |
9 |
Correct |
3 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
308 KB |
Output is correct |
9 |
Correct |
3 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 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 |
332 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 |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
304 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 |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
308 KB |
Output is correct |
9 |
Correct |
3 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 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 |
332 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 |
3 ms |
204 KB |
Output is correct |
24 |
Correct |
3 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
296 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
304 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 |
0 ms |
332 KB |
Output is correct |
35 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
36 |
Halted |
0 ms |
0 KB |
- |