# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
806711 |
2023-08-04T09:07:55 Z |
Arturgo |
Maze (JOI23_ho_t3) |
C++14 |
|
49 ms |
10696 KB |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator + (const pair<int, int>& a, const pair<int, int>& b) {
return {a.first + b.first, a.second + b.second};
}
int nbLigs, nbCols, cote;
int lDeb, cDeb, lFin, cFin;
vector<string> terrain;
bool estDans(pair<int, int> p) {
return p.first >= 0 && p.second >= 0
&& p.first < nbLigs && p.second < nbCols;
}
vector<pair<int, int>> aExplorer;
vector<vector<bool>> explorees, dansAExplorer;
pair<int, int> deps[4] = {
{0, 1},
{1, 0},
{0, -1},
{-1, 0}
};
vector<pair<int, int>> expand(vector<pair<int, int>> cells,
pair<int, int> dir) {
vector<pair<int, int>> nouvCells;
for(pair<int, int> cell : cells) {
pair<int, int> nxt = cell + dir;
if(estDans(nxt)
&& !dansAExplorer[nxt.first][nxt.second]) {
aExplorer.push_back(nxt);
terrain[nxt.first][nxt.second] = '.';
dansAExplorer[nxt.first][nxt.second] = true;
nouvCells.push_back(nxt);
}
}
return nouvCells;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> nbLigs >> nbCols >> cote;
cin >> lDeb >> cDeb >> lFin >> cFin;
lDeb--; cDeb--; lFin--; cFin--;
for(int iLig = 0;iLig < nbLigs;iLig++) {
string lig;
cin >> lig;
terrain.push_back(lig);
}
explorees = vector<vector<bool>>(
nbLigs, vector<bool>(nbCols, false)
);
dansAExplorer = vector<vector<bool>>(
nbLigs, vector<bool>(nbCols, false)
);
dansAExplorer[lDeb][cDeb] = true;
aExplorer.push_back({lDeb, cDeb});
int dist = 0;
while(true) {
vector<pair<int, int>> murs;
while(!aExplorer.empty()) {
pair<int, int> cell = aExplorer.back();
aExplorer.pop_back();
if(terrain[cell.first][cell.second] == '#') {
murs.push_back({cell.first, cell.second});
}
else {
explorees[cell.first][cell.second] = true;
for(pair<int, int> dep : deps) {
pair<int, int> nxt = cell + dep;
if(estDans(nxt) && !dansAExplorer[nxt.first][nxt.second]) {
dansAExplorer[nxt.first][nxt.second] = true;
aExplorer.push_back(nxt);
}
}
}
}
if(explorees[lFin][cFin]) {
break;
}
dist++;
vector<pair<int, int>> cells = murs;
for(pair<int, int> cell : cells) {
aExplorer.push_back(cell);
terrain[cell.first][cell.second] = '.';
dansAExplorer[cell.first][cell.second] = true;
}
vector<pair<int, int>> vues = murs;
for(int iFois = 0;iFois < cote - 1;iFois++) {
cells = expand(cells, deps[0]);
vues.insert(vues.end(), cells.begin(), cells.end());
cells = expand(cells, deps[2]);
vues.insert(vues.end(), cells.begin(), cells.end());
}
for(int iFois = 0;iFois < cote - 1;iFois++) {
vues = expand(vues, deps[1]);
vues = expand(vues, deps[3]);
}
}
cout << dist << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
728 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
500 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
6 ms |
612 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
1744 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
5 ms |
636 KB |
Output is correct |
34 |
Correct |
3 ms |
736 KB |
Output is correct |
35 |
Correct |
7 ms |
736 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
4 ms |
724 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
49 ms |
2484 KB |
Output is correct |
40 |
Correct |
2 ms |
576 KB |
Output is correct |
41 |
Correct |
3 ms |
812 KB |
Output is correct |
42 |
Correct |
8 ms |
668 KB |
Output is correct |
43 |
Correct |
6 ms |
660 KB |
Output is correct |
44 |
Correct |
8 ms |
1240 KB |
Output is correct |
45 |
Correct |
14 ms |
1444 KB |
Output is correct |
46 |
Correct |
40 ms |
10696 KB |
Output is correct |
47 |
Correct |
43 ms |
2628 KB |
Output is correct |
48 |
Correct |
39 ms |
2484 KB |
Output is correct |
49 |
Correct |
16 ms |
3320 KB |
Output is correct |
50 |
Correct |
45 ms |
3320 KB |
Output is correct |
51 |
Correct |
37 ms |
3348 KB |
Output is correct |
52 |
Correct |
25 ms |
2816 KB |
Output is correct |
53 |
Correct |
42 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
728 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
500 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
6 ms |
612 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
1744 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
5 ms |
636 KB |
Output is correct |
34 |
Correct |
3 ms |
736 KB |
Output is correct |
35 |
Correct |
7 ms |
736 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
4 ms |
724 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
49 ms |
2484 KB |
Output is correct |
40 |
Correct |
2 ms |
576 KB |
Output is correct |
41 |
Correct |
3 ms |
812 KB |
Output is correct |
42 |
Correct |
8 ms |
668 KB |
Output is correct |
43 |
Correct |
6 ms |
660 KB |
Output is correct |
44 |
Correct |
8 ms |
1240 KB |
Output is correct |
45 |
Correct |
14 ms |
1444 KB |
Output is correct |
46 |
Correct |
40 ms |
10696 KB |
Output is correct |
47 |
Correct |
43 ms |
2628 KB |
Output is correct |
48 |
Correct |
39 ms |
2484 KB |
Output is correct |
49 |
Correct |
16 ms |
3320 KB |
Output is correct |
50 |
Correct |
45 ms |
3320 KB |
Output is correct |
51 |
Correct |
37 ms |
3348 KB |
Output is correct |
52 |
Correct |
25 ms |
2816 KB |
Output is correct |
53 |
Correct |
42 ms |
2516 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
728 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
500 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
6 ms |
612 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
1744 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
5 ms |
636 KB |
Output is correct |
34 |
Correct |
3 ms |
736 KB |
Output is correct |
35 |
Correct |
7 ms |
736 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
4 ms |
724 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
49 ms |
2484 KB |
Output is correct |
40 |
Correct |
2 ms |
576 KB |
Output is correct |
41 |
Correct |
3 ms |
812 KB |
Output is correct |
42 |
Correct |
8 ms |
668 KB |
Output is correct |
43 |
Correct |
6 ms |
660 KB |
Output is correct |
44 |
Correct |
8 ms |
1240 KB |
Output is correct |
45 |
Correct |
14 ms |
1444 KB |
Output is correct |
46 |
Correct |
40 ms |
10696 KB |
Output is correct |
47 |
Correct |
43 ms |
2628 KB |
Output is correct |
48 |
Correct |
39 ms |
2484 KB |
Output is correct |
49 |
Correct |
16 ms |
3320 KB |
Output is correct |
50 |
Correct |
45 ms |
3320 KB |
Output is correct |
51 |
Correct |
37 ms |
3348 KB |
Output is correct |
52 |
Correct |
25 ms |
2816 KB |
Output is correct |
53 |
Correct |
42 ms |
2516 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
728 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
500 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
472 KB |
Output is correct |
29 |
Correct |
6 ms |
612 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
1744 KB |
Output is correct |
32 |
Correct |
5 ms |
596 KB |
Output is correct |
33 |
Correct |
5 ms |
636 KB |
Output is correct |
34 |
Correct |
3 ms |
736 KB |
Output is correct |
35 |
Correct |
7 ms |
736 KB |
Output is correct |
36 |
Correct |
3 ms |
852 KB |
Output is correct |
37 |
Correct |
4 ms |
724 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
49 ms |
2484 KB |
Output is correct |
40 |
Correct |
2 ms |
576 KB |
Output is correct |
41 |
Correct |
3 ms |
812 KB |
Output is correct |
42 |
Correct |
8 ms |
668 KB |
Output is correct |
43 |
Correct |
6 ms |
660 KB |
Output is correct |
44 |
Correct |
8 ms |
1240 KB |
Output is correct |
45 |
Correct |
14 ms |
1444 KB |
Output is correct |
46 |
Correct |
40 ms |
10696 KB |
Output is correct |
47 |
Correct |
43 ms |
2628 KB |
Output is correct |
48 |
Correct |
39 ms |
2484 KB |
Output is correct |
49 |
Correct |
16 ms |
3320 KB |
Output is correct |
50 |
Correct |
45 ms |
3320 KB |
Output is correct |
51 |
Correct |
37 ms |
3348 KB |
Output is correct |
52 |
Correct |
25 ms |
2816 KB |
Output is correct |
53 |
Correct |
42 ms |
2516 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |