結果
| 問題 |
No.2411 Reverse Directions
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-12 01:41:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,639 bytes |
| コンパイル時間 | 2,506 ms |
| コンパイル使用メモリ | 194,676 KB |
| 実行使用メモリ | 823,076 KB |
| 最終ジャッジ日時 | 2024-11-18 21:43:09 |
| 合計ジャッジ時間 | 37,555 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 11 WA * 9 TLE * 8 MLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60;
const int IINF = (1 << 30) - 1;
template<typename T> struct Edge{
int to; T w;
Edge(int to_, T w_=1){
to = to_;
w=w_;
}
};
template<typename T> using Tree = vector<vector<Edge<T>>>;
template<typename T> using Graph = vector<vector<Edge<T>>>;
/* 容量&重み付きエッジ for Dinic */
template<typename T> struct REdge{
int to;
T cap;
T cost;
int rev;
REdge(int to_, T cap_, T cost_=1){
to = to_;
cap = cap_;
cost = cost_;
}
REdge(int to_, T cap_, T cost_, int rev_){
to = to_;
cap = cap_;
cost = cost_;
rev = rev_;
}
};
/* 残余グラフ for Dinic */
template<typename T> using RGraph = vector<vector<REdge<T>>>;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll H, W, K, L, R;
cin >> H >> W >> K >> L >> R;
vector<string> S(H); rep(i, H) cin >> S[i];
if((H+W-2)%2 != K%2){
cout << "No" << endl;
return 0;
}
ll di[4] = {0, 0, 1, -1};
ll dj[4] = {1, -1, 0, 0};
char ddir[4] = {'R', 'L', 'D', 'U'};
char rdir[4] = {'L', 'R', 'U', 'D'};
map<char, ll> alloc;
alloc['R'] = 0;
alloc['L'] = 1;
alloc['D'] = 2;
alloc['U'] = 3;
queue<pll> Q;
vector<vector<ll>> sdist(H, vector<ll>(W, -1));
vector<vector<string>> sdir(H, vector<string>(W, ""));
sdist[0][0] = 0;
Q.push({0, 0});
while(!Q.empty()){
ll now_i = Q.front().fi;
ll now_j = Q.front().se;
Q.pop();
rep(k, 4){
ll nxt_i = now_i + di[k];
ll nxt_j = now_j + dj[k];
if(nxt_i<0||nxt_j<0||H<=nxt_i||W<=nxt_j) continue;
if(S[nxt_i][nxt_j]=='#') continue;
if(sdist[nxt_i][nxt_j]!=-1) continue;
sdist[nxt_i][nxt_j] = sdist[now_i][now_j]+1;
sdir[nxt_i][nxt_j] = sdir[now_i][now_j]+ddir[k];
Q.push({nxt_i, nxt_j});
}
}
vector<vector<ll>> tdist(H, vector<ll>(W, -1));
vector<vector<string>> tdir(H, vector<string>(W, ""));
tdist[H-1][W-1] = 0;
Q.push({H-1, W-1});
while(!Q.empty()){
ll now_i = Q.front().fi;
ll now_j = Q.front().se;
Q.pop();
rep(k, 4){
ll nxt_i = now_i + di[k];
ll nxt_j = now_j + dj[k];
if(nxt_i<0||nxt_j<0||H<=nxt_i||W<=nxt_j) continue;
if(S[nxt_i][nxt_j]=='#') continue;
if(tdist[nxt_i][nxt_j]!=-1) continue;
tdist[nxt_i][nxt_j] = tdist[now_i][now_j]+1;
tdir[nxt_i][nxt_j] = rdir[k] + tdir[now_i][now_j];
Q.push({nxt_i, nxt_j});
}
}
//L-1回目の行動後の到達頂点
for(ll si=0; si<H; si++) for(ll sj=0; sj<W; sj++){
if((si+sj)%2 != (L-1)%2) continue;
if(sdist[si][sj]>L-1) continue;
if(S[si][sj]=='#') continue;
string ans = "";
//1~L-1回目までの移動
ans += sdir[si][sj];
ll x = alloc[ans.back()];
rep(k, (L-1-sdist[si][sj])/2){
ans += rdir[x];
ans += ddir[x];
}
//横側を確認
if(0<=sj-1 && sj+1<W){
if(S[si][sj-1]=='.' && S[si][sj+1]=='.'){
if((R-L+1)%2==0 && tdist[si][sj]>=K-R){
//okデス
//L~R回目までの移動
rep(k, (R-L+1)/2){
ans+="LR";
}
//R+1~K回目までの行動
ans+=tdir[si][sj];
x = alloc[tdir[si][sj].back()];
ll tmp = K-(ll)ans.size();
rep(k, tmp/2){
ans+=rdir[x];
ans+=ddir[x];
}
cout << ans << endl;
return 0;
}else if((R-L+1)%2==1 && tdist[si][sj-1]>=K-R){
//okデス
//L~R回目までの移動
rep(k, (R-L+1)/2){
ans+="LR";
}
ans+="L";
//R+1~K回目までの行動
ans+=tdir[si][sj-1];
x = alloc[tdir[si][sj-1].back()];
ll tmp = K-(ll)ans.size();
rep(k, tmp/2){
ans+=rdir[x];
ans+=ddir[x];
}
cout << "Yes" << endl;
cout << ans << endl;
return 0;
}
}
}
//縦側を確認
if(0<=si-1 && si+1<H){
if(S[si-1][sj]=='.' && S[si+1][sj]=='.'){
if((R-L+1)%2==0 && tdist[si][sj]>=K-R){
//okデス
//L~R回目までの移動
rep(k, (R-L+1)/2){
ans+="UD";
}
//R+1~K回目までの行動
ans+=tdir[si][sj];
x = alloc[tdir[si][sj].back()];
ll tmp = K-(ll)ans.size();
rep(k, tmp/2){
ans+=rdir[x];
ans+=ddir[x];
}
cout << "Yes" << endl;
cout << ans << endl;
return 0;
}else if((R-L+1)%2==1 && tdist[si-1][sj]>=K-R){
//okデス
//L~R回目までの移動
rep(k, (R-L+1)/2){
ans+="UD";
}
ans+="U";
//R+1~K回目までの行動
ans+=tdir[si-1][sj];
x = alloc[tdir[si-1][sj].back()];
ll tmp = K-(ll)ans.size();
rep(k, tmp/2){
ans+=rdir[x];
ans+=ddir[x];
}
cout << "Yes" << endl;
cout << ans << endl;
return 0;
}
}
}
}
cout << "No" << endl;
}