結果
| 問題 | No.2411 Reverse Directions | 
| コンテスト | |
| ユーザー |  rniya | 
| 提出日時 | 2023-08-11 22:03:20 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 16 ms / 2,000 ms | 
| コード長 | 3,350 bytes | 
| コンパイル時間 | 2,854 ms | 
| コンパイル使用メモリ | 209,228 KB | 
| 最終ジャッジ日時 | 2025-02-16 01:25:10 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 | 
ソースコード
#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 k = 0; k < (R - L) / 2 + (f - A[i][j]) / 2 + (g - B[i][j]) / 2; k++) 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;
}
            
            
            
        