結果

問題 No.2411 Reverse Directions
ユーザー 👑 emthrmemthrm
提出日時 2023-08-11 22:26:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,134 bytes
コンパイル時間 3,446 ms
コンパイル使用メモリ 264,156 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-29 13:27:27
合計ジャッジ時間 7,250 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w, k, l, r; cin >> h >> w >> k >> l >> r; --l; --r;
  if ((r - l + 1) % 2 == 1) {
    cout << "No\n";
    return 0;
  }
  vector<string> s(h); REP(i, h) cin >> s[i];
  const auto can_visit = [&](const int sy, const int sx, const int length) -> pair<vector<vector<int>>, vector<vector<int>>> {
    vector dist(h, vector(w, -1)), prv(h, vector(w, -1));
    dist[sy][sx] = 0;
    for (queue<pair<int, int>> que({{sy, sx}}); !que.empty(); que.pop()) {
      const auto [i, j] = que.front();
      if (dist[i][j] == length) break;
      REP(k, 4) {
        const int y = i + DY4[k], x = j + DX4[k];
        if (0 <= y && y < h && 0 <= x && x < w && s[y][x] == '.' && dist[y][x] == -1) {
          dist[y][x] = dist[i][j] + 1;
          prv[y][x] = (k + 2) % 4;
          que.emplace(y, x);
        }
      }
    }
    REP(i, h) REP(j, w) {
      if (dist[i][j] != -1 && (length - dist[i][j]) % 2 == 1) dist[i][j] = -1;
    }
    return {dist, prv};
  };
  const auto [dist1, prv1] = can_visit(0, 0, l);
  const auto [dist2, prv2] = can_visit(h - 1, w - 1, k - 1 - r);
  REP(i, h) REP(j, w) {
    if (dist1[i][j] != -1 && dist2[i][j] != -1 &&
        ((i > 0 && i + 1 < h && s[i - 1][j] == '.' && s[i + 1][j] == '.') ||
         (j > 0 && j + 1 < w && s[i][j - 1] == '.' && s[i][j + 1] == '.'))) {
      string s1 = "", s2 = "";
      for (int y = i, x = j; y != 0 || x != 0;) {
        const int k = prv1[y][x];
        if (k == 0) s1 += 'U';
        if (k == 1) s1 += 'R';
        if (k == 2) s1 += 'D';
        if (k == 3) s1 += 'L';
        y += DY4[k];
        x += DX4[k];
      }
      ranges::reverse(s1);
      for (int y = i, x = j; y != h - 1 || x != w - 1;) {
        const int k = prv2[y][x];
        if (k == 0) s2 += 'D';
        if (k == 1) s2 += 'L';
        if (k == 2) s2 += 'U';
        if (k == 3) s2 += 'R';
        y += DY4[k];
        x += DX4[k];
      }
      cout << "Yes\n" << s1;
      if (i > 0 && i + 1 < h && s[i - 1][j] == '.' && s[i + 1][j] == '.') {
        for (int j = l; j <= r; j += 2) {
          cout << "UD";
        }
      } else {
        for (int j = l; j <= r; j += 2) {
          cout << "LR";
        }
      }
      cout << s2 << '\n';
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}
0