結果

問題 No.2411 Reverse Directions
ユーザー umezoumezo
提出日時 2023-08-11 22:59:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,615 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 211,728 KB
実行使用メモリ 9,996 KB
最終ジャッジ日時 2024-04-29 14:09:00
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};
int dist[505][505];
int dist1[505][505];
const int INF=1e9;
pair<int,int> pre[505][505];
pair<int,int> pre1[505][505];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  rep(i,505) rep(j,505) dist[i][j]=INF;
  rep(i,505) rep(j,505) dist1[i][j]=INF;
  
  int h,w,k,l,r;
  cin>>h>>w>>k>>l>>r;
  vector<string> S(h);
  rep(i,h) cin>>S[i];
  
  if((r-l)%2==0 || h+w-2>k || (h+w)%2!=k%2){
    cout<<"No"<<endl;
    return 0;
  }
  
  queue<pair<int,int>> que;
  que.push({0,0});
  dist[0][0]=0;
  pre[0][0]={-1,-1};
  while(que.size()){
    auto t=que.front(); que.pop();
    int i=t.first,j=t.second;
    rep(k,4){
      int ni=i+dh[k],nj=j+dw[k];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(S[ni][nj]=='#') continue;
      if(dist[i][j]+1<dist[ni][nj]){
        dist[ni][nj]=dist[i][j]+1;
        que.push({ni,nj});
        pre[ni][nj]={i,j};
      }
    }
  }
  if(dist[h-1][w-1]==INF){
    cout<<"No"<<endl;
    return 0;
  }
  
  que.push({h-1,w-1});
  dist1[h-1][w-1]=0;
  pre1[h-1][w-1]={-1,-1};
  while(que.size()){
    auto t=que.front(); que.pop();
    int i=t.first,j=t.second;
    rep(k,4){
      int ni=i+dh[k],nj=j+dw[k];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(S[ni][nj]=='#') continue;
      if(dist1[i][j]+1<dist1[ni][nj]){
        dist1[ni][nj]=dist1[i][j]+1;
        que.push({ni,nj});
        pre1[ni][nj]={i,j};
      }
    }
  }

  rep(i,h) rep(j,w){
    if((i+j)%2==l%2) continue;
    if(dist[i][j]>=l) continue;
    if(dist1[i][j]>k-r) continue;
    if(j>0 && j<w-1 && dist[i][j-1]!=INF && dist[i][j+1]!=INF){
      cout<<"Yes"<<endl;
      int d=k-dist[i][j]-dist1[i][j];
      string a,b,c;
      int ni=i,nj=j;
      while(1){
        int p=pre[ni][nj].first,q=pre[ni][nj].second;
        ni=p,nj=q;
        if(ni==-1) break;
        if(i<ni) a+="U";
        else if(i>ni) a+="D";
        else if(j<nj) a+="L";
        else a+="R";
      }
      reverse(ALL(a));
      rep(k,d/2) b+="RL";
      ni=i,nj=j;
      while(1){
        int p=pre1[ni][nj].first,q=pre1[ni][nj].second;
        ni=p,nj=q;
        if(ni==-1) break;
        if(i<ni) c+="D";
        else if(i>ni) c+="U";
        else if(j<nj) c+="R";
        else c+="L";
      }
      cout<<a<<b<<c<<endl;
      return 0;
    }
    if(i>0 && i<h-1 && dist[i-1][j]!=INF && dist[i+1][j]!=INF){
      cout<<"Yes"<<endl;
      
      return 0;
    }
  }
  cout<<"No"<<endl;
  
  return 0;
}
0