結果
問題 | No.2411 Reverse Directions |
ユーザー |
![]() |
提出日時 | 2023-08-11 23:56:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,124 bytes |
コンパイル時間 | 2,352 ms |
コンパイル使用メモリ | 209,428 KB |
最終ジャッジ日時 | 2025-02-16 02:27:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 7 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/all>using namespace std;//using namespace atcoder;//using mint = modint1000000007;//const int mod = 1000000007;//using mint = modint998244353;//const int mod = 998244353;const int INF = 1e9;//const long long LINF = 1e18;#define rep(i, n) for (int i = 0; i < (n); ++i)#define rep2(i,l,r)for(int i=(l);i<(r);++i)#define rrep(i, n) for (int i = (n-1); i >= 0; --i)#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)#define all(x) (x).begin(),(x).end()#define allR(x) (x).rbegin(),(x).rend()#define endl "\n"#define P pair<int,int>template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }const int dx[] = { 1,0,-1,0 };const int dy[] = { 0,-1,0,1 };char cr[] = { 'U','R','D','L' };char cr2[] = { 'D','L','U','R' };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);rep(i, h)cin >> s[i];if (0 == (r - l) % 2) {cout << "No" << endl;return 0;}vector<vector<int>> dp(h, vector<int>(w, INF));vector<vector<int>> dpR(h, vector<int>(w, INF));rep(_, 2) {queue<pair<int, int>> q;if (0 == _) {q.emplace(0, 0);dp[0][0] = 0;}else {q.emplace(h - 1, w - 1);dp[h - 1][w - 1] = 0;}while (!q.empty()) {int x = q.front().first;int y = q.front().second;q.pop();rep(i, 4) {int nx = x + dx[i];int ny = y + dy[i];if ((0 <= nx) && (h > nx) && (0 <= ny) && (w > ny) && ('#' != s[nx][ny])) {if (chmin(dp[nx][ny], dp[x][y] + 1)) q.emplace(nx, ny);}}}swap(dp, dpR);}if (0 != abs(dp[h - 1][w - 1] - k) % 2) {cout << "No" << endl;return 0;}auto f = [&](int x, int y)->string {string ret;while (0 != dp[x][y]) {rep(i, 4) {int nx = x + dx[i];int ny = y + dy[i];if (nx < 0)continue;if (ny < 0)continue;if (nx >= h)continue;if (ny >= w)continue;char c = cr[i];if (dp[nx][ny] + 1 == dp[x][y]) {x = nx;y = ny;ret += c;break;}}}return ret;};rep(i, h)rep(j, w) {if (INF == dp[i][j])continue;int he = dp[i][j];int ta = dpR[i][j];int bo = k - he - ta;if (he >= l)continue;if (bo < 0)continue;if (he + bo < r)continue;if ((0 != j) && ('.' == s[i][j - 1]) && (w != j + 1) && ('.' == s[i][j + 1])) {string ans0 = f(i, j);reverse(all(ans0));swap(dp, dpR);swap(cr, cr2);string ans1;rep(i, bo / 2)ans1 += "LR";string ans2 = f(i, j);cout << "Yes" << endl;cout << ans0 + ans1 + ans2 << endl;return 0;}if ((0 != i) && ('.' == s[i - 1][j]) && (h != (i + 1)) && ('.' == s[i + 1][j])) {string ans0 = f(i, j);reverse(all(ans0));swap(dp, dpR);swap(cr, cr2);string ans1;rep(i, bo / 2)ans1 += "DU";string ans2 = f(i, j);cout << "Yes" << endl;cout << ans0 + ans1 + ans2 << endl;return 0;}}cout << "No" << endl;return 0;}