結果

問題 No.2411 Reverse Directions
ユーザー rniyarniya
提出日時 2023-08-11 21:53:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,310 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 212,800 KB
実行使用メモリ 9,456 KB
最終ジャッジ日時 2023-08-11 21:53:47
合計ジャッジ時間 6,824 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 8 ms
9,456 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 7 ms
5,416 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 14 ms
6,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

const string dir = "DRUL";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W, K, L, R;
    cin >> H >> W >> K >> L >> R;
    vector<string> S(H);
    cin >> S;
    L--;

    if ((R - L) & 1) {
        cout << "No\n";
        return 0;
    }
    auto calc = [&](int sx, int sy) -> pair<vector<vector<int>>, vector<vector<int>>> {
        vector res(H, vector<int>(W, INF)), pre(H, vector<int>(W, -1));
        queue<pair<int, int>> que;
        res[sx][sy] = 0;
        que.emplace(sx, sy);
        while (not que.empty()) {
            auto [x, y] = que.front();
            que.pop();
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 or H <= nx or ny < 0 or W <= ny) continue;
                if (S[nx][ny] == '#') continue;
                if (res[nx][ny] != INF) continue;
                res[nx][ny] = res[x][y] + 1;
                pre[nx][ny] = i;
                que.emplace(nx, ny);
            }
        }
        return {res, pre};
    };
    auto [A, preA] = calc(0, 0);
    auto [B, preB] = calc(H - 1, W - 1);
    int f = L, g = K - R;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] > f or B[i][j] > g) continue;
            if ((f - A[i][j]) & 1) continue;
            if ((g - B[i][j]) & 1) continue;
            int ok = 0;
            if (i - 1 >= 0 and i + 1 < H and S[i - 1][j] == '.' and S[i + 1][j] == '.') ok |= 1;
            if (j - 1 >= 0 and j + 1 < W and S[i][j - 1] == '.' and S[i][j + 1] == '.') ok |= 2;
            if (ok == 0) continue;
            string ans = "";
            for (int x = i, y = j; preA[x][y] != -1;) {
                int d = preA[x][y];
                ans += dir[d];
                x -= dx[d], y -= dy[d];
            }
            reverse(all(ans));
            for (int i = 0; i < (R - L) / 2; i++) ans += (ok & 1 ? "DU" : "LR");
            for (int x = i, y = j; preB[x][y] != -1;) {
                int d = preB[x][y] ^ 2;
                ans += dir[d];
                x += dx[d], y += dy[d];
            }
            cout << "Yes\n";
            cout << ans << '\n';
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}
0