結果
| 問題 | No.2411 Reverse Directions | 
| コンテスト | |
| ユーザー |  umezo | 
| 提出日時 | 2023-08-11 22:59:01 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,615 bytes | 
| コンパイル時間 | 2,275 ms | 
| コンパイル使用メモリ | 204,548 KB | 
| 最終ジャッジ日時 | 2025-02-16 01:59:18 | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 13 | 
ソースコード
#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;
}
            
            
            
        