結果

問題 No.2411 Reverse Directions
ユーザー Taiki0715Taiki0715
提出日時 2023-08-11 22:46:59
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,412 bytes
コンパイル時間 4,124 ms
コンパイル使用メモリ 182,312 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-29 13:55:11
合計ジャッジ時間 7,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,504 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }
  string ans="";
  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&&dst2[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);
            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;
                }
              }
              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;
                }
              }
              if(x==h-1&&y==w-1)break;
            }
            if(ans.size()==k){
              cout<<"Yes"<<endl<<ans<<endl;
              return;
            }
            else ans.clear();
          }
        }
      }
    }
  }
  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&&dst2[i][j]!=1e9){
        if(dst[i][j]<l){
          if(dst2[i][j]<=k-r&&(k-r-dst2[i][j])%2==0){
            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;
                }
              }
              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;
                }
              }
              if(x==h-1&&y==w-1)break;
            }
            if(ans.size()==k){
              cout<<"Yes"<<endl<<ans<<endl;
              return;
            }
            else ans.clear();
          }
        }
      }
    }
  }
  cout<<"No"<<endl;
}
0