結果
| 問題 |
No.2411 Reverse Directions
|
| コンテスト | |
| ユーザー |
Taiki0715
|
| 提出日時 | 2023-08-11 22:26:10 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 5,482 bytes |
| コンパイル時間 | 4,542 ms |
| コンパイル使用メモリ | 181,180 KB |
| 実行使用メモリ | 11,200 KB |
| 最終ジャッジ日時 | 2024-11-18 17:04:19 |
| 合計ジャッジ時間 | 44,633 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 4 TLE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcount(x)
ll myceil(ll a,ll b){return (a+b-1)/b;}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
void SOLVE();
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
clock_t start=clock();
#endif
int testcase=1;
//cin>>testcase;
for(int i=0;i<testcase;i++){
SOLVE();
}
#ifdef LOCAL
cout<<"time:";
cout<<(clock()-start)/1000;
cout<<"ms\n";
#endif
}
vector<int>dx{1,0,-1,0},dy{0,1,0,-1};
int h,w;
bool inarea(int x,int y){
if(x<0)return false;
if(y<0)return false;
if(x>h-1)return false;
if(y>w-1)return false;
return true;
}
void SOLVE(){
int k,l,r;
cin>>h>>w>>k>>l>>r;
vector<string>s(h);
cin>>s;
if((r-l)%2==0){
cout<<"No"<<endl;
return;
}
vector<vector<int>>dst(h,vector<int>(w,1e9));
dst[0][0]=0;
queue<pair<int,int>>que;
que.push({0,0});
while(!que.empty()){
auto [x,y]=que.front();
que.pop();
rep(i,4){
int cx=x+dx[i],cy=y+dy[i];
if(inarea(cx,cy)&&s[cx][cy]=='.'&&chmin(dst[cx][cy],dst[x][y]+1))que.push({cx,cy});
}
}
vector<vector<int>>dst2(h,vector<int>(w,1e9));
dst2[h-1][w-1]=0;
que.push({h-1,w-1});
while(!que.empty()){
auto [x,y]=que.front();
que.pop();
rep(i,4){
int cx=x+dx[i],cy=y+dy[i];
if(inarea(cx,cy)&&s[cx][cy]=='.'&&chmin(dst2[cx][cy],dst2[x][y]+1))que.push({cx,cy});
}
}
if(dst[h-1][w-1]==1e9){
cout<<"No"<<endl;
return;
}
if((dst[h-1][w-1]-k)%2==1){
cout<<"No"<<endl;
}
if(dst[h-1][w-1]>k){
cout<<"No"<<endl;
return;
}
reps(i,1,h-1)rep(j,w){
if(s[i][j]=='.'&&s[i-1][j]=='.'&&s[i+1][j]=='.'){
if(dst[i][j]!=1e9){
debug(i,j);
if(dst[i][j]<l){
debug(i,j);
if(dst2[i][j]<=k-r&&(k-r-dst2[i][j])%2==0){
debug(i,j);
string ans="";
int x=i,y=j;
while(true){
rep(o,4){
int cx=x+dx[o],cy=y+dy[o];
if(inarea(cx,cy)&&dst[cx][cy]==dst[x][y]-1){
x=cx,y=cy;
ans+="ULDR"[o];
break;
}
assert(o!=3);
}
if(x==0&&y==0)break;
}
reverse(all(ans));
while(ans.size()<r)ans+="UD";
x=i,y=j;
while(true){
rep(o,4){
int cx=x+dx[o],cy=y+dy[o];
if(inarea(cx,cy)&&dst2[cx][cy]==dst2[x][y]-1){
x=cx,y=cy;
ans+="DRUL"[o];
break;
}
assert(o!=3);
}
if(x==h-1&&y==w-1)break;
}
if(ans.size()==k){
cout<<"Yes\n"<<ans<<endl;
return;
}
}
}
}
}
}
rep(i,h)reps(j,1,w-1){
if(s[i][j]=='.'&&s[i][j-1]=='.'&&s[i][j+1]=='.'){
if(dst[i][j]!=1e9){
if(dst[i][j]<l){
if(dst2[i][j]<=k-r&&(k-r-dst2[i][j])%2==0){
string ans="";
int x=i,y=j;
while(true){
rep(o,4){
int cx=x+dx[o],cy=y+dy[o];
if(inarea(cx,cy)&&dst[cx][cy]==dst[x][y]-1){
x=cx,y=cy;
ans+="ULDR"[o];
break;
}
assert(o!=3);
}
if(x==0&&y==0)break;
}
reverse(all(ans));
while(ans.size()<r)ans+="LR";
x=i,y=j;
while(true){
rep(o,4){
int cx=x+dx[o],cy=y+dy[o];
if(inarea(cx,cy)&&dst2[cx][cy]==dst2[x][y]-1){
x=cx,y=cy;
ans+="DRUL"[o];
break;
}
assert(o!=3);
}
if(x==h-1&&y==w-1)break;
}
if(ans.size()==k){
cout<<"Yes\n"<<ans<<endl;
return;
}
}
}
}
}
}
debug("No");
cout<<"No"<<endl;
}
Taiki0715