QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152419 | #6422. Evil Coordinate | qzez# | AC ✓ | 19ms | 11812kb | C++14 | 1.5kb | 2023-08-28 08:06:57 | 2023-08-28 08:06:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e5+10;
int T,n,px,py;
char a[N];
int L,R,U,D;
string ans;
bool dfs(int x,int y){
if(x==px&&y==py)return 0;
if(!(L+R+U+D)){
cout<<ans<<'\n';return 1;
}
if(x==px&&!L&&!R&&(y<py)!=(y+U-D<py))return 0;
if(y==py&&!U&&!D&&(x<px)!=(x+R-L<px))return 0;
if(L){
L--;
ans+='L';
if(dfs(x-1,y))return 1;
ans.pop_back();
L++;
}
if(R){
R--;
ans+='R';
if(dfs(x+1,y))return 1;
ans.pop_back();
R++;
}
if(U){
U--;
ans+='U';
if(dfs(x,y+1))return 1;
ans.pop_back();
U++;
}
if(D){
D--;
ans+='D';
if(dfs(x,y-1))return 1;
ans.pop_back();
D++;
}
// debug(L,R,D,U,px-x,py-y);
return 0;
}
void get(){
scanf("%d%d%s",&px,&py,a+1),n=strlen(a+1);
L=0,R=0,D=0,U=0;
for(int i=1;i<=n;i++){
L+=a[i]=='L';
R+=a[i]=='R';
D+=a[i]=='D';
U+=a[i]=='U';
}
if(px==R-L&&py==U-D)puts("Impossible");
else{
ans="";
if(!dfs(0,0))puts("Impossible");
}
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 10ms
memory: 11812kb
input:
11109 6 0 RUDUDR 2 0 URU 0 0 UDRU 0 0 R -1 1 LDUUDDRUUL -1 5 RRUUUDUUU -8 4 RRDRLDR 2 0 UD 0 0 UUDD 3 -2 LDDLLLRR 3 -2 LDRURLDD 1 0 RRL -1 0 DUDDLLRDU -4 0 LL -1 -1 DLRLDLUDUR 1 4 URDULUR 0 0 DDUUDUDDDD 0 2 UU 1 0 RRULD 0 -2 LDLRLLDRRL 0 1 RLRLLRLUR -3 0 RL 0 0 D 0 0 L 0 0 DDLRRUDRUD 0 0 DULU 2 0 RR...
output:
RRUUDD RUU Impossible Impossible Impossible RRUUUUUUD LRRRRDD UD Impossible LLLLRRDD LLRRUDDD Impossible RLUUDDDLD LL Impossible LRRUUUD Impossible Impossible Impossible LLLLLRRRDD Impossible LR Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU LLLUD Impossible LUUUDDD RRUUDD Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 19ms
memory: 11676kb
input:
11107 1 0 LLRLRURLR 1 0 LLRR 0 1 R 1 0 LLLRLRRR 1 0 RUL 0 1 UD 1 0 RLRLU 0 1 DDDUUUDU 1 0 RURRLLRLL 1 0 LRLR 1 0 ULR 0 1 R 0 1 DDUUUDR 0 1 UUDDUDDU 0 1 DDUUDU 1 0 RRLRLLRLRL 1 0 RLRRLL 1 0 LUR 1 0 U 1 0 LRRRLLLR 0 1 DRUUDDUDU 0 1 DUUDDUR 1 0 LRLRLR 0 1 UUDDDUDU 0 1 R 0 1 UDUDDU 0 1 DUUDUD 1 0 RRLRRR...
output:
LLLLRRRRU LLRR R LLLLRRRR LRU DU LLRRU DUDUDUDU LLLLRRRRU LLRR LRU R RUUUDDD DUDUDUDU DUDUDU LLLLLRRRRR LLLRRR LRU U LLLLRRRR RUUUUDDDD RUUUDDD LLLRRR DUDUDUDU R DUDUDU DUDUDU LLLLLRRRRR DUDUDUDU DUDU LLLLRRRRU DUDU LLLRRR LRU LRU U LRU LLLRRR LLLLLRRRRR U DUDUDU R LLLRRR RUUUUDDDD RUUUUDDDD LLLRRR ...
result:
ok 11107 cases