QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876620 | #5514. Maze | A_programmer | 0 | 0ms | 0kb | C++17 | 1.7kb | 2025-01-31 09:12:19 | 2025-01-31 09:12:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 6e6 + 5;
const int inf = 0x3f3f3f3f;
struct node
{
pii pos;
int d, l;
};
deque<node> q;
char str[maxn];
vector<bool> A[maxn], vis[maxn];
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int main()
{
freopen("c.in", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0);
pii s, e;
int n, m, k; cin >> n >> m >> k;
cin >> s.first >> s.second >> e.first >> e.second;
for (int i = 1; i <= n; i++)
{
cin >> str + 1, A[i].resize(m + 1), vis[i].resize(m + 1);
for (int j = 1; j <= m; j++) A[i][j] = (str[j] == '#');
}
q.push_back((node){s, 0, 0}), vis[s.first][s.second] = 1;
while (q.size())
{
node nw = q.front(); q.pop_front();
if (nw.pos == e) return cout << nw.d, 0;
if (nw.l)
{
nw.l--;
for (int i = 0; i < 8; i++)
{
node tmp = nw;
int x = (tmp.pos.first += dx[i]), y = (tmp.pos.second += dy[i]);
if (x <= 0 || x > n || y <= 0 || y > m || vis[x][y]) continue;
vis[x][y] = 1, q.push_back(tmp);
}
}
else
{
for (int i = 0; i < 4; i++)
{
node tmp = nw;
int x = (tmp.pos.first += dx[i]), y = (tmp.pos.second += dy[i]);
if (x <= 0 || x > n || y <= 0 || y > m || vis[x][y]) continue;
if (!A[x][y]) vis[x][y] = 1, q.push_front(tmp);
else vis[x][y] = 1, tmp.d++, tmp.l = k - 1, q.push_back(tmp);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
31 32 1 25 22 5 3 ################################ ################################ .############################### .############################### ##..###############.############ ###.###############.############ #####.########################## ###.#.########################## ###.##############...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #52:
score: 0
Runtime Error
input:
3 6 2 2 1 3 3 ...### ..##.. #..###
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #64:
score: 0
Runtime Error
input:
35 60 20 3 60 2 44 .#....##.#.###..##.#.#....#.....#..#..#.##.#..#....###.####. #.#......#.####..####...#...#......#........####....##.#.### .#..#.....#.####..#.##..#.#.#...#.##..#.#..#######....#..##. .#.#...##..#.##.......#......##......####...##.##..##.#....# #...#.......#..#..#...#.#####.##.###....
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%