Submission #65684512


Source Code Expand

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

template <typename Tp>
struct Triplet {
    Tp x, y, z;
};

const int MAXN = 1e3 + 5, INF = 1e9 + 5,
mov[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
char s[MAXN][MAXN],
arrow[] = {'^', 'v', '<', '>'};
int d[MAXN][MAXN];
queue<Triplet<int>> Q;

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i ++) {
        for (int j = 1; j <= W; j ++) {
            cin >> s[i][j];
            if (s[i][j] != '.') {
                d[i][j] = INF;
            }
            if (s[i][j] == 'E') {
                Q.push({i, j, 0});
            }
        }
    }
    while (!Q.empty()) {
        auto [x, y, e] = Q.front();
        Q.pop();
        for (auto [u, v] : mov) {
            if (1 <= x + u && x + u <= H &&
                1 <= y + v && y + v <= W &&
                !d[x + u][y + v]) {
                d[x + u][y + v] = e + 1;
                Q.push({x + u, y + v, e + 1});
            }
        }
    }
    for (int i = 1; i <= H; i ++) {
        for (int j = 1; j <= W; j ++) {
            if (s[i][j] == '.') {
                for (int k = 0; k < 4; k ++) {
                    auto [u, v] = mov[k];
                    if (1 <= i + u && i + u <= H &&
                        1 <= j + v && j + v <= W &&
                        (d[i][j] > d[i + u][j + v] || s[i + u][j + v] == 'E')) {
                        s[i][j] = arrow[k];
                        break;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= H; i ++) {
        for (int j = 1; j <= W; j ++) {
            cout << s[i][j];
        }
        cout << '\n';
    }
    return 0;
}

Submission Info

Submission Time
Task D - Escape Route
User FlowerAccepted
Language C++ 17 (gcc 12.2)
Score 400
Code Size 1837 Byte
Status AC
Exec Time 52 ms
Memory 14432 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 25
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 02_corner_03.txt, 02_corner_04.txt, 02_corner_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3444 KiB
00_sample_01.txt AC 1 ms 3624 KiB
00_sample_02.txt AC 1 ms 3464 KiB
01_random_00.txt AC 30 ms 10584 KiB
01_random_01.txt AC 27 ms 10348 KiB
01_random_02.txt AC 47 ms 12748 KiB
01_random_03.txt AC 39 ms 9776 KiB
01_random_04.txt AC 31 ms 10160 KiB
01_random_05.txt AC 36 ms 11424 KiB
01_random_06.txt AC 35 ms 10636 KiB
01_random_07.txt AC 46 ms 10960 KiB
01_random_08.txt AC 24 ms 13108 KiB
01_random_09.txt AC 24 ms 8560 KiB
01_random_10.txt AC 33 ms 8728 KiB
01_random_11.txt AC 52 ms 14100 KiB
01_random_12.txt AC 48 ms 14432 KiB
01_random_13.txt AC 37 ms 9208 KiB
01_random_14.txt AC 37 ms 10144 KiB
01_random_15.txt AC 45 ms 10864 KiB
02_corner_00.txt AC 27 ms 8264 KiB
02_corner_01.txt AC 18 ms 8216 KiB
02_corner_02.txt AC 32 ms 14096 KiB
02_corner_03.txt AC 1 ms 3504 KiB
02_corner_04.txt AC 3 ms 8384 KiB
02_corner_05.txt AC 33 ms 8344 KiB