QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506005 | #6422. Evil Coordinate | Timeless123 | WA | 10ms | 3700kb | C++17 | 4.4kb | 2024-08-05 14:37:31 | 2024-08-05 14:37:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18
int x,y;
string s;
void solve()
{
cin>>x>>y;
cin>>s;
if(!x && !y)
{
cout<<"Impossible"<<'\n';
return ;
}
int L=0,R=0,U=0,D=0;
for(int i=0;i<s.size();++i)
{
if(s[i]=='U') U++;
else if(s[i]=='D') D++;
else if(s[i]=='R') R++;
else L++;
}
if(U - D == y && R - L == x)
{
cout<<"Impossible"<<'\n';
return ;
}
if(x!=0 && y!=0)
{
if(x>0 && y>0)
{
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=R;++i) cout<<'R';
}
else if(x<0 && y>0)
{
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=U;++i) cout<<'U';
}
else if(x<0 && y<0)
{
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=D;++i) cout<<'D';
}
else if(x>0 && y<0)
{
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=R;++i) cout<<'R';
}
}
else if(x==0 && y!=0)
{
if(!(L+R))
{
if(y<0)
{
if(D > U && abs(D-U)>=abs(y))
{
cout<<"Impossible"<<'\n';
return ;
}
else
{
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=D;++i) cout<<'D';
}
}
else
{
if(U > D && abs(D-U)>=abs(y))
{
cout<<"Impossible"<<'\n';
return ;
}
else
{
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=U;++i) cout<<'U';
}
}
}
else
{
if(y>0)
{
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=U;++i) cout<<'U';
}
else
{
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=D;++i) cout<<'D';
}
}
}
else
{
if(!(L+R))
{
if(x<0)
{
if(L > R && abs(L-R)>=abs(x))
{
cout<<"Impossible"<<'\n';
return ;
}
else
{
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=L;++i) cout<<'L';
}
}
else
{
if(R > L && abs(R-L)>=abs(x))
{
cout<<"Impossible"<<'\n';
return ;
}
else
{
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=R;++i) cout<<'R';
}
}
}
else
{
if(x>0)
{
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=D;++i) cout<<'D';
for(int i=1;i<=U;++i) cout<<'U';
}
else
{
for(int i=1;i<=R;++i) cout<<'R';
for(int i=1;i<=L;++i) cout<<'L';
for(int i=1;i<=U;++i) cout<<'U';
for(int i=1;i<=D;++i) cout<<'D';
}
}
}
cout<<'\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1; cin>>_;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLDUURR UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3700kb
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:
RRDDUU RUU Impossible Impossible Impossible RRDUUUUUU RRRRLDD Impossible LLLLDDRR ULLDDDRR Impossible RLLUUDDDD LL Impossible LDUUURR Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU ULLLD Impossible LUUUDDD UUDDRR Impossibl...
result:
wrong answer Line "" doesn't correspond to pattern "[UDLR]{1,100000}|Impossible"