QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506107 | #6422. Evil Coordinate | pagohia | WA | 21ms | 3908kb | C++14 | 3.2kb | 2024-08-05 15:20:40 | 2024-08-05 15:20:42 |
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)
{
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;
}
详细
Test #1:
score: 100
Accepted
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 Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 3808kb
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 UUUUUURRD RRRRLDD DU Impossible RRLLLLDD URRLLDDD Impossible RUUDDDDLL LL Impossible RRUUUDL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible UURRRRRLLL LLLUD Impossible UUULDDD RRUUDD Impossi...
result:
wrong answer case 28, participant's output goes through forbidden coordinate