QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419094 | #6422. Evil Coordinate | wiseman123# | WA | 0ms | 3444kb | C++20 | 3.2kb | 2024-05-23 17:48:46 | 2024-05-23 17:48:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool check(string s,int x,int y)
{
int x1=0,y1=0;
for (int i=0;i<s.size();i++)
{
if (x1==x&&y1==y)
{
return false;
}
if (s[i]=='U') y1++;
if (s[i]=='D') y1--;
if (s[i]=='L') x1--;
if (s[i]=='R') x1++;
}
if (x1==x&&y1==y)
{
return false;
}
return true;
}
void solve()
{
int x,y;
cin>>x>>y;
int n=0,m=0;
int x1=0,y1=0;
string s;
cin>>s;
int len=s.size();
for (int i=0;i<s.size();i++)
{
if (s[i]=='U') m++;
if (s[i]=='D') m--;
if (s[i]=='L') n--;
if (s[i]=='R') n++;
}
// cout<<n<<" "<<m<<" "<<x<<" "<<y<<endl;
int flag=check(s,x,y);
if (flag)
{
cout<<s<<endl;
return ;
}
if (x==n&&y==m)
{
cout<<"Impossible"<<endl;
return ;
}
if (x==0&&y==0)
{
cout<<"Impossible"<<endl;
return ;
}
if (n==0)
{
// cout<<len<<" "<<y<<endl;
if (len-abs(m)==0)
{
cout<<"Impossible"<<endl;
return ;
}
string s1="",s2="";
int k=(len-abs(y))/2;
for (int i=1;i<=len;i++)
{
if (i<=k)
{
s1+='L';
s2+='R';
}
else if(i>len-k)
{
s1+='R';
s2+='L';
}
else
{
if (y>0)
{
s1+='U',s2+='U';
}
else
{
s1+='D',s2+='D';
}
}
}
flag=check(s1,x,y);
if (flag)
{
cout<<s1<<endl;
return ;
}
cout<<s2<<endl;
return ;
}
if (m==0)
{
if (len-abs(m)==0)
{
cout<<"Impossible"<<endl;
return ;
}
string s1="",s2="";
int k=(len-abs(x))/2;
// cout<<k<<endl;
for (int i=1;i<=len;i++)
{
if (i<=k)
{
s1+='U';
s2+='D';
}
else if(i>len-k)
{
s1+='D';
s2+='U';
}
else
{
if (x>0)
{
s1+='R',s2+='R';
}
else
{
s1+='L',s2+='L';
}
}
}
flag=check(s1,x,y);
if (flag)
{
cout<<s1<<endl;
return ;
}
cout<<s2<<endl;
return ;
}
if (len>abs(n)+abs(m))
{
if (x!=0||y!=1)
{
for (int i=1;i<=len-abs(n)-abs(m);i++)
{
if (i%2==1)
{
cout<<"U";
}
else
{
cout<<"D";
}
}
}
else
{
for (int i=1;i<=len-abs(n)-abs(m);i++)
{
if (i%2==1)
{
cout<<"D";
}
else
{
cout<<"U";
}
}
}
}
if (n>0)
{
string s1="",s2="";
for (int i=1;i<=n;i++)
{
s1+='R';
}
if (m>0)
{
for (int i=1;i<=m;i++)
{
s1+='U';
s2+='U';
}
}
else
{
for (int i=1;i<=abs(m);i++)
{
s1+='D';
s2+='D';
}
}
for (int i=1;i<=n;i++)
{
s2+='R';
}
flag=check(s1,x,y);
if (flag)
{
cout<<s1<<endl;
return ;
}
cout<<s2<<endl;
return ;
}
if (n<0)
{
string s1="",s2="";
for (int i=1;i<=abs(n);i++)
{
s1+='L';
}
if (m>0)
{
for (int i=1;i<=m;i++)
{
s1+='U';
s2+='U';
}
}
else
{
for (int i=1;i<=abs(m);i++)
{
s1+='D';
s2+='D';
}
}
for (int i=1;i<=abs(n);i++)
{
s2+='L';
}
flag=check(s1,x,y);
if (flag)
{
cout<<s1<<endl;
return ;
}
cout<<s2<<endl;
return ;
}
}
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: 3444kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLLURRR UUU Impossible Impossible Impossible
result:
wrong answer case 1, participant's output is not a permutation of the input