提出 #74868818


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef priority_queue<int,vi,greater<int>> mipqint;
typedef priority_queue<int> pqint;
#define SZ(x) ((int)x.size())
const int mod = 1e9+7;
const int P = 998244353;
const int md = 101;
const ll inf = (1LL << 60LL);
const int N = 2e5+10;

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const char dc[] = "UDLR";
struct Node {
    int x, y, d;
};
struct Pre {
    int x, y, d;
    char c;
} pre[1005][1005][5];
bool vis[1005][1005][5];
char s[1005][1005];
int H, W;
int sx, sy, gx, gy;
bool in(int x, int y) {
    return x >= 0 && x < H && y >= 0 && y < W;
}
int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
        for (int j = 0; j < W; j++) {
            if (s[i][j] == 'S') sx = i, sy = j;
            if (s[i][j] == 'G') gx = i, gy = j;
        }
    }
    memset(vis, 0, sizeof(vis));
    queue<Node> q;
    q.push({sx, sy, 4});
    vis[sx][sy][4] = 1;
    int found = -1;
    while (!q.empty()) {
        auto [x, y, d] = q.front();
        q.pop();

        if (x == gx && y == gy) {
            found = d;
            break;
        }
        for (int to = 0; to < 4; to++) {
            int nx = x + dx[to];
            int ny = y + dy[to];
            if (!in(nx, ny) || s[nx][ny] == '#') continue;
            bool ok = 1;
            if (d != 4) {
                if (s[x][y] == 'o') {
                    if (to != d) ok = 0;
                } else if (s[x][y] == 'x') {
                    if (to == d) ok = 0;
                }
            }

            if (!ok) continue;
            if (vis[nx][ny][to]) continue;

            vis[nx][ny][to] = 1;
            pre[nx][ny][to] = {x, y, d, dc[to]};
            q.push({nx, ny, to});
        }
    }

    if (found == -1) {
        cout << "No\n";
        return 0;
    }
    string path;
    int x = gx, y = gy, d = found;
    while (!(x == sx && y == sy)) {
        auto p = pre[x][y][d];
        path += p.c;
        x = p.x;
        y = p.y;
        d = p.d;
    }
    reverse(path.begin(), path.end());

    cout << "Yes\n" << path << '\n';
    return 0;
}

提出情報

提出日時
問題 D - Go Straight
ユーザ wuqize
言語 C++23 (GCC 15.2.0)
得点 425
コード長 2446 Byte
結果 AC
実行時間 229 ms
メモリ 91624 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 3
AC × 46
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 3 ms 8412 KiB
example_01.txt AC 3 ms 8592 KiB
example_02.txt AC 3 ms 8440 KiB
hand_00.txt AC 101 ms 88076 KiB
hand_01.txt AC 15 ms 13404 KiB
hand_02.txt AC 224 ms 91624 KiB
hand_03.txt AC 229 ms 91624 KiB
hand_04.txt AC 3 ms 8508 KiB
hand_05.txt AC 102 ms 87928 KiB
hand_06.txt AC 79 ms 89656 KiB
hand_07.txt AC 100 ms 87972 KiB
hand_08.txt AC 14 ms 9664 KiB
hand_09.txt AC 3 ms 8628 KiB
random_00.txt AC 14 ms 9560 KiB
random_01.txt AC 110 ms 83928 KiB
random_02.txt AC 36 ms 28792 KiB
random_03.txt AC 13 ms 9308 KiB
random_04.txt AC 61 ms 47096 KiB
random_05.txt AC 84 ms 76280 KiB
random_06.txt AC 14 ms 9336 KiB
random_07.txt AC 13 ms 9304 KiB
random_08.txt AC 34 ms 29708 KiB
random_09.txt AC 62 ms 55268 KiB
random_10.txt AC 64 ms 57252 KiB
random_11.txt AC 71 ms 62932 KiB
random_12.txt AC 79 ms 69368 KiB
random_13.txt AC 13 ms 9488 KiB
random_14.txt AC 54 ms 48316 KiB
random_15.txt AC 13 ms 10348 KiB
random_16.txt AC 13 ms 9780 KiB
random_17.txt AC 13 ms 10036 KiB
random_18.txt AC 13 ms 10872 KiB
random_19.txt AC 15 ms 13368 KiB
random_20.txt AC 12 ms 9552 KiB
random_21.txt AC 29 ms 47756 KiB
random_22.txt AC 13 ms 9548 KiB
random_23.txt AC 14 ms 10616 KiB
random_24.txt AC 34 ms 55016 KiB
random_25.txt AC 19 ms 23800 KiB
random_26.txt AC 13 ms 10664 KiB
random_27.txt AC 75 ms 79864 KiB
random_28.txt AC 13 ms 9436 KiB
random_29.txt AC 21 ms 23988 KiB
random_30.txt AC 24 ms 32980 KiB
random_31.txt AC 55 ms 81368 KiB
random_32.txt AC 19 ms 19576 KiB