結果

問題 No.2411 Reverse Directions
ユーザー kwm_tkwm_t
提出日時 2023-08-11 23:37:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,082 bytes
コンパイル時間 2,967 ms
コンパイル使用メモリ 215,040 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-29 14:50:08
合計ジャッジ時間 5,824 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 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 5 ms
5,376 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 3 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
			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);
			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;
}
0