QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#149265 | #6422. Evil Coordinate | ylf | WA | 17ms | 3728kb | C++14 | 6.8kb | 2023-08-24 11:32:02 | 2023-08-24 11:32:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=3e5+10;
ll t,x,y,n;
char s[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--)
{
ll u=0,d=0,l=0,r=0;
cin>>x>>y;
cin>>(s+1);
n=strlen(s+1);
for(ll a=1;a<=n;a++)
{
if(s[a]=='U') u++;
else if(s[a]=='D') d++;
else if(s[a]=='L') l++;
else r++;
}
if(u-d==y&&r-l==x) cout<<"Impossible";
else
{
if(y==0)
{
if(x==0) cout<<"Impossible";
else if(x<0)
{
if(u==d)
{
if(u==0)
{
if(r-l>x)
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
}
else
{
cout<<"Impossible";
}
}
else
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
else
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
}
}
else//x>0
{
if(u==d)
{
if(u==0)
{
if(r-l<x)
{
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=r;a++) cout<<"R";
}
else
{
cout<<"Impossible";
}
}
else
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
else
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
}
}
}
else if(y>0)
{
if(x==0)
{
if(l==r)
{
if(l==0)
{
if(u-d>y) cout<<"Impossible";
else
{
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=u;a++) cout<<"U";
}
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=l;a++) cout<<"L";
}
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
else
{
if(r-l==x)
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
}
else
{
if(x==0)
{
if(l==r)
{
if(l==0)
{
if(u-d<y) cout<<"Impossible";
else
{
for(ll a=1;a<=d;a++) cout<<"d";
for(ll a=1;a<=u;a++) cout<<"U";
}
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=l;a++) cout<<"L";
}
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
else
{
if(r-l==x)
{
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
}
else
{
for(ll a=1;a<=r;a++) cout<<"R";
for(ll a=1;a<=l;a++) cout<<"L";
for(ll a=1;a<=u;a++) cout<<"U";
for(ll a=1;a<=d;a++) cout<<"D";
}
}
}
}
cout<<"\n";
}
}
//https://cftracker.netlify.app/contests
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
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: 17ms
memory: 3728kb
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 UUR Impossible Impossible Impossible RRUUUUUUD RRRRLDD UD Impossible RRLLLLDD RRLLUDDD Impossible UUDDDDRLL LL Impossible UUUDRRL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU LLLUD Impossible UUULDDD UUDDRR Impossi...
result:
wrong answer Line "dddUUUUU" doesn't correspond to pattern "[UDLR]{1,100000}|Impossible"