結果
問題 | No.2411 Reverse Directions |
ユーザー | Taiki0715 |
提出日時 | 2023-08-11 22:36:52 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,488 bytes |
コンパイル時間 | 5,593 ms |
コンパイル使用メモリ | 181,812 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-11-18 17:30:24 |
合計ジャッジ時間 | 45,528 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,636 KB |
testcase_01 | AC | 1 ms
12,680 KB |
testcase_02 | AC | 1 ms
13,636 KB |
testcase_03 | AC | 2 ms
11,684 KB |
testcase_04 | AC | 6 ms
13,636 KB |
testcase_05 | AC | 2 ms
10,528 KB |
testcase_06 | AC | 2 ms
13,632 KB |
testcase_07 | AC | 4 ms
10,788 KB |
testcase_08 | AC | 2 ms
13,636 KB |
testcase_09 | AC | 2 ms
11,428 KB |
testcase_10 | TLE | - |
testcase_11 | WA | - |
testcase_12 | TLE | - |
testcase_13 | AC | 2 ms
10,532 KB |
testcase_14 | TLE | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
13,632 KB |
testcase_17 | TLE | - |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
11,568 KB |
testcase_20 | WA | - |
testcase_21 | AC | 5 ms
6,820 KB |
testcase_22 | TLE | - |
testcase_23 | AC | 2 ms
6,816 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
ソースコード
#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(inarea(i,j)&&inarea(i-1,j)&&inarea(i+1,j)&&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); 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; } } 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; } } } } } } rep(i,h)reps(j,1,w-1){ if(inarea(i,j)&&inarea(i,j-1)&&inarea(i,j+1)&&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){ 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+="ULDRPPPPPPP"[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+="DRULPPPPPP"[o]; break; } } if(x==h-1&&y==w-1)break; } if(ans.size()==k){ cout<<"Yes"<<endl<<ans<<endl; return; } } } } } } cout<<"No"<<endl; }