結果
| 問題 |
No.2411 Reverse Directions
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2023-08-11 22:28:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,170 bytes |
| コンパイル時間 | 3,431 ms |
| コンパイル使用メモリ | 265,940 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2024-11-18 17:08:20 |
| 合計ジャッジ時間 | 9,121 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 1 WA * 13 RE * 15 |
ソースコード
#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) {
assert(false);
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;
}
}
assert(false);
cout << "No\n";
return 0;
}
emthrm