結果
問題 | No.2411 Reverse Directions |
ユーザー | Taiki0715 |
提出日時 | 2023-08-11 22:32:53 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,486 bytes |
コンパイル時間 | 4,333 ms |
コンパイル使用メモリ | 183,464 KB |
実行使用メモリ | 13,648 KB |
最終ジャッジ日時 | 2024-11-18 17:18:51 |
合計ジャッジ時間 | 43,888 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,636 KB |
testcase_01 | AC | 2 ms
12,764 KB |
testcase_02 | AC | 1 ms
13,632 KB |
testcase_03 | AC | 2 ms
11,808 KB |
testcase_04 | AC | 6 ms
13,640 KB |
testcase_05 | AC | 2 ms
10,532 KB |
testcase_06 | AC | 2 ms
13,644 KB |
testcase_07 | AC | 5 ms
10,784 KB |
testcase_08 | AC | 2 ms
13,648 KB |
testcase_09 | AC | 1 ms
11,432 KB |
testcase_10 | TLE | - |
testcase_11 | WA | - |
testcase_12 | TLE | - |
testcase_13 | AC | 2 ms
10,656 KB |
testcase_14 | TLE | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
13,636 KB |
testcase_17 | TLE | - |
testcase_18 | WA | - |
testcase_19 | AC | 1 ms
11,700 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,816 KB |
testcase_26 | AC | 2 ms
6,820 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(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; } 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&&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+="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; }