QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506097 | #6422. Evil Coordinate | pagohia | WA | 0ms | 3908kb | C++14 | 2.9kb | 2024-08-05 15:15:26 | 2024-08-05 15:15:26 |
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)
{
if(y==0&&x>=0&&r-l>=x)
cout<<"Impossible"<<endl;
else if(y==0&&x<0&&r-l<=x)
cout<<"Impossible"<<endl;
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)
{
if(x==0&&y>=0&&u-d>=y)
cout<<"Impossible"<<endl;
else if(x==0&&y<0&&u-d<=y)
cout<<"Impossible"<<endl;
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)
{
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)
{
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: 0
Wrong Answer
time: 0ms
memory: 3908kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
UURRLLD UUU Impossible UUU Impossible UUU Impossible
result:
wrong answer case 4, participant's output goes through forbidden coordinate