結果
問題 | No.2411 Reverse Directions |
ユーザー | polylogK |
提出日時 | 2023-08-11 22:22:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,651 bytes |
コンパイル時間 | 2,334 ms |
コンパイル使用メモリ | 216,708 KB |
実行使用メモリ | 8,004 KB |
最終ジャッジ日時 | 2024-11-18 16:53:05 |
合計ジャッジ時間 | 5,041 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 18 ms
8,004 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 3 ms
6,816 KB |
testcase_14 | AC | 7 ms
6,820 KB |
testcase_15 | WA | - |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 9 ms
6,816 KB |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
6,816 KB |
testcase_20 | AC | 8 ms
6,820 KB |
testcase_21 | AC | 3 ms
6,820 KB |
testcase_22 | WA | - |
testcase_23 | AC | 4 ms
6,820 KB |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 3 ms
6,816 KB |
testcase_28 | AC | 13 ms
6,816 KB |
testcase_29 | AC | 22 ms
6,820 KB |
testcase_30 | WA | - |
testcase_31 | AC | 4 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cerr; using std::cin; using std::cout; using std::endl; #if defined(DONLINE_JUDGE) #define NDEBUG #elif defined(ONLINE_JUDGE) #define NDEBUG #endif template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int h, w, k, l, r; scanf("%d%d%d%d%d", &h, &w, &k, &l, &r); std::vector<std::string> s(h); for (auto& v : s) std::cin >> v; --l; const int LEFT = l; const int RIGHT = k - r; if ((k % 2 != (h + w) % 2) or (r - l) % 2) { puts("No"); return 0; } std::vector<int> dy{0, 1, 0, -1}; std::vector<int> dx{1, 0, -1, 0}; std::string tos = "RDLU"; auto f = [&](int sy, int sx) { std::vector d(h, std::vector<int>(w, 1 << 30)); d[sy][sx] = 0; std::queue<std::pair<int, int>> qu({{sy, sx}}); while (!qu.empty()) { auto [y, x] = qu.front(); qu.pop(); for (int k = 0; k < 4; ++k) { const int ny = y + dy[k]; const int nx = x + dx[k]; if (nx < 0 or ny < 0 or nx >= w or ny >= h) continue; if (s[ny][nx] == '#') continue; if (d[ny][nx] != 1 << 30) continue; qu.push({ny, nx}); d[ny][nx] = d[y][x] + 1; } } return d; }; auto d0 = f(0, 0); auto dn = f(h - 1, w - 1); int fy, fx, fd; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (d0[i][j] > LEFT) continue; if (dn[i][j] > RIGHT) continue; if (d0[i][j] % 2 != LEFT % 2) continue; int dir = -1; for (int k = 0; k < 4; ++k) { const int ny = i + dy[k]; const int nx = j + dx[k]; if (nx < 0 or ny < 0 or nx >= w or ny >= h) continue; if (s[ny][nx] == '#') continue; dir = k; } if (dir == -1) continue; fy = i; fx = j; fd = dir; goto answer; } } puts("No"); return 0; answer: std::string ans; auto df = f(fy, fx); { int y = 0, x = 0; while (y != fy or x != fx) { for (int k = 0; k < 4; ++k) { const int ny = y + dy[k]; const int nx = x + dx[k]; if (nx < 0 or ny < 0 or nx >= w or ny >= h) continue; if (s[ny][nx] == '#') continue; if (d0[y][x] + 1 + df[ny][nx] != df[0][0]) continue; ans += tos[k]; y = ny; x = nx; break; } } r = k - dn[fy][fx]; while (ans.size() < r) { ans += tos[fd]; ans += tos[(fd + 2) % 4]; } while (y != h - 1 or x != w - 1) { for (int k = 0; k < 4; ++k) { const int ny = y + dy[k]; const int nx = x + dx[k]; if (nx < 0 or ny < 0 or nx >= w or ny >= h) continue; if (s[ny][nx] == '#') continue; if (df[y][x] + 1 + dn[ny][nx] != df[h - 1][w - 1]) continue; ans += tos[k]; y = ny; x = nx; break; } } puts("Yes"); std::cout << ans << std::endl; } return 0; }