# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043113 |
2024-08-03T23:42:05 Z |
biank |
Maze (JOI23_ho_t3) |
C++14 |
|
1 ms |
456 KB |
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
const int INF = 1e9;
using ii = pair<int, int>;
queue<ii> q;
int h, w;
vector<string> g;
vector<vector<bool>> vis;
void push(int x, int y) {
vis[x][y] = true;
q.emplace(x, y);
}
void expand(string colors, vector<ii> moves, int distance = INF) {
while (!q.empty() && distance--) {
int s = sz(q);
queue<ii> copy = q;
while (s--) {
auto [x, y] = q.front();
q.pop();
for (auto [dx, dy] : moves) {
int nx = x + dx, ny = y + dy;
if (nx >= 0 && nx < h && ny >= 0 && ny < w && !vis[nx][ny]) {
bool valid = false;
for (char c : colors) if (g[nx][ny] == c) valid = true;
if (valid) push(nx, ny);
}
}
}
if (q.empty()) {
q = copy;
break;
}
}
}
const vector<ii> ALL_MOVES = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const vector<ii> VERTICAL = {{0, 1}, {0, -1}};
const vector<ii> HORIZONTAL = {{1, 0}, {-1, 0}};
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int k, s_r, s_c, g_r, g_c;
cin >> h >> w >> k >> s_r >> s_c >> g_r >> g_c;
--s_r, --s_c, --g_r, --g_c;
g.resize(h);
vis.assign(h, vector<bool>(w, false));
for (int i = 0; i < h; i++) cin >> g[i];
push(s_r, s_c);
expand(".", ALL_MOVES);
int ops = 0;
while (!vis[g_r][g_c]) {
expand("#", ALL_MOVES, 1);
expand(".#", VERTICAL, k - 1);
expand(".#", HORIZONTAL, k - 1);
expand(".", ALL_MOVES);
ops++;
}
cout << ops << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'void expand(std::string, std::vector<std::pair<int, int> >, int)':
Main.cpp:26:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | auto [x, y] = q.front();
| ^
Main.cpp:28:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for (auto [dx, dy] : moves) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |