QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876620#5514. MazeA_programmer0 0ms0kbC++171.7kb2025-01-31 09:12:192025-01-31 09:12:21

Judging History

This is the latest submission verdict.

  • [2025-01-31 09:12:21]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-31 09:12:19]
  • Submitted

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;
}

详细

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%