QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506431 | #6422. Evil Coordinate | pagohia | WA | 18ms | 3824kb | C++14 | 4.1kb | 2024-08-05 17:24:10 | 2024-08-05 17:24:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 100005
void solve()
{
int x,y;
string str1="";
char str[N];
cin>>x>>y;
cin>>str;
int u=0;
int d=0;
int l=0;
int r=0;
for(int i=0;i<strlen(str);i++)
{
if(str[i]=='U')
u++;
else if(str[i]=='D')
d++;
else if(str[i]=='L')
l++;
else if(str[i]=='R')
r++;
}
if(x==0&&y==0)
cout<<"Impossible"<<endl;
else if((l||r)&&!u&&!d)
{
int xx=1;
if(y==0&&x>=0&&r-l>=x)
{
cout<<"Impossible"<<endl;
xx=0;
}
else if(y==0&&x<0&&r-l<=x)
{
cout<<"Impossible"<<endl;
xx=0;
}
if(xx==1)
{
if(x>=0)
{
for(int i=0;i<l;i++)
str1+='L';
for(int i=0;i<r;i++)
str1+='R';
cout<<str1<<endl;
}
else if(x<0)
{
for(int i=0;i<r;i++)
str1+='R';
for(int i=0;i<l;i++)
str1+='L';
cout<<str1<<endl;
}
}
}
else if((u||d)&&!l&&!r)
{
int xx=1;
if(x==0&&y>=0&&u-d>=y)
{
cout<<"Impossible"<<endl;
xx=0;
}
else if(x==0&&y<0&&u-d<=y)
{
cout<<"Impossible"<<endl;
xx=0;
}
if(xx==1)
{
if(y>=0)
{
for(int i=0;i<d;i++)
str1+='D';
for(int i=0;i<u;i++)
str1+='U';
cout<<str1<<endl;
}
else if(y<0)
{
for(int i=0;i<u;i++)
str1+='U';
for(int i=0;i<d;i++)
str1+='D';
cout<<str1<<endl;
}
}
}
else if(r-l==x&&u-d==y)
cout<<"Impossible"<<endl;
else
{
int dx=r-l;
int dy=u-d;
if(dx==x&&dy!=y)
{
if(x>0&&x<=r)
{
for(int i=0;i<x-1;i++)
str1+='R';
for(int i=0;i<u;i++)
str1+='U';
for(int i=0;i<d;i++)
str1+='D';
for(int i=x-1;i<r;i++)
str1+='R';
for(int i=0;i<l;i++)
str1+='L';
cout<<str1<<endl;
}
else
{
for(int i=0;i<r;i++)
str1+='R';
for(int i=0;i<u;i++)
str1+='U';
for(int i=0;i<d;i++)
str1+='D';
for(int i=0;i<l;i++)
str1+='L';
cout<<str1<<endl;
}
}
else if(dy==y&&dx!=x)
{
if(y>0&&y<=u)
{
for(int i=0;i<y-1;i++)
str1+='U';
for(int i=0;i<r;i++)
str1+='R';
for(int i=0;i<l;i++)
str1+='L';
for(int i=y-1;i<u;i++)
str1+='U';
for(int i=0;i<d;i++)
str1+='D';
cout<<str1<<endl;
}
else
{
for(int i=0;i<u;i++)
str1+='U';
for(int i=0;i<r;i++)
str1+='R';
for(int i=0;i<l;i++)
str1+='L';
for(int i=0;i<d;i++)
str1+='D';
cout<<str1<<endl;
}
}
else
{
for(int i=0;i<r;i++)
str1+='R';
for(int i=0;i<l;i++)
str1+='L';
for(int i=0;i<u;i++)
str1+='U';
for(int i=0;i<d;i++)
str1+='D';
cout<<str1<<endl;
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
RRLLUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 3824kb
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:
UURRDD RUU Impossible Impossible Impossible UUUURRUUD RRRRLDD DU Impossible RRLLLLDD URRLLDDD Impossible RUUDDDDLL LL Impossible UUUDRRL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible URRRRRLLLU LLLUD Impossible UUULDDD RUUDDR Impossi...
result:
wrong answer case 42, participant's output goes through forbidden coordinate