QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152416 | #6422. Evil Coordinate | qzez# | TL | 1ms | 3488kb | C++14 | 1.5kb | 2023-08-28 08:05:24 | 2023-08-28 08:05:25 |
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+R-L<py))return 0;
if(y==py&&!U&&!D&&(x<px)!=(x+U-D<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++;
}
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: 1ms
memory: 3488kb
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: -100
Time Limit Exceeded
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...