QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506002 | #6422. Evil Coordinate | Timeless123 | WA | 8ms | 3768kb | C++17 | 4.4kb | 2024-08-05 14:34:03 | 2024-08-05 14:34:03 |
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 == x && R - L == y)
{
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 8ms
memory: 3768kb
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 RLLDDDUUUU RRDUUUUUU RRRRLDD Impossible LLLLDDRR ULLDDDRR LRR RLLUUDDDD LL Impossible LDUUURR Impossible Impossible LRRDU LLLLLRRRDD LLLLRRRRU RL Impossible Impossible Impossible Impossible LLLLRRRRRR LLLRRRRRUU ULLLD R LUUUDDD UUDDRR RRRLLLL RRLUUDD RRDDUUUUU UUURR...
result:
wrong answer case 5, participant's output goes through forbidden coordinate