QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619397 | #6422. Evil Coordinate | xDarkbluex# | AC ✓ | 31ms | 3940kb | C++14 | 3.6kb | 2024-10-07 14:05:29 | 2024-10-07 14:05:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,mx,my;
int cu,cd,cl,cr;
string s;
void UD()
{
if(mx==0&&my==1)
{
for(int i=1;i<=min(cu,cd);i++)
{
printf("DU");
}
}
else
{
for(int i=1;i<=min(cu,cd);i++)
{
printf("UD");
}
}
}
void LR()
{
if(mx==1&&my==0)
{
for(int i=1;i<=min(cl,cr);i++)
{
printf("LR");
}
}
else
{
for(int i=1;i<=min(cl,cr);i++)
{
printf("RL");
}
}
}
void solve()
{
scanf("%lld%lld",&mx,&my);
cin>>s;
cu=cd=cl=cr=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='U')
{
cu++;
}
else if(s[i]=='D')
{
cd++;
}
else if(s[i]=='L')
{
cl++;
}
else if(s[i]=='R')
{
cr++;
}
}
if(mx==0&&my==0)
{
printf("Impossible\n");
return ;
}
if(mx==cr-cl&&my==cu-cd)
{
printf("Impossible\n");
return ;
}
if(cu==cd&&cl==cr)
{
UD();
LR();
}
else if(cu==cd&&cl!=cr)
{
if(my==0)
{
if(cu==0&&mx*(cr-cl)>=0&&abs(mx)<=abs(cr-cl))
{
printf("Impossible\n");
return ;
}
if(cu==0)
{
LR();
if(cl>cr)
{
for(int i=1;i<=cl-cr;i++)
{
printf("L");
}
}
else
{
for(int i=1;i<=cr-cl;i++)
{
printf("R");
}
}
}
else
{
for(int i=1;i<=cu;i++)
{
printf("U");
}
for(int i=1;i<=cl;i++)
{
printf("L");
}
for(int i=1;i<=cr;i++)
{
printf("R");
}
for(int i=1;i<=cd;i++)
{
printf("D");
}
}
}
else
{
UD();
LR();
if(cl>cr)
{
for(int i=1;i<=cl-cr;i++)
{
printf("L");
}
}
else
{
for(int i=1;i<=cr-cl;i++)
{
printf("R");
}
}
}
}
else if(cu!=cd&&cl==cr)
{
if(mx==0)
{
if(cl==0&&my*(cu-cd)>=0&&abs(my)<=abs(cu-cd))
{
printf("Impossible\n");
return ;
}
if(cl==0)
{
UD();
if(cu>cd)
{
for(int i=1;i<=cu-cd;i++)
{
printf("U");
}
}
else
{
for(int i=1;i<=cd-cu;i++)
{
printf("D");
}
}
}
else
{
for(int i=1;i<=cl;i++)
{
printf("L");
}
for(int i=1;i<=cu;i++)
{
printf("U");
}
for(int i=1;i<=cd;i++)
{
printf("D");
}
for(int i=1;i<=cr;i++)
{
printf("R");
}
}
}
else
{
UD();
LR();
if(cu>cd)
{
for(int i=1;i<=cu-cd;i++)
{
printf("U");
}
}
else
{
for(int i=1;i<=cd-cu;i++)
{
printf("D");
}
}
}
}
else
{
UD();
LR();
if((mx==0&&my*(cu-cd)>=0&&abs(my)<=abs(cu-cd))||(my==cu-cd&&mx*(cr-cl)>=0&&abs(mx)<=abs(cr-cl)))
{
if(cl>cr)
{
for(int i=1;i<=cl-cr;i++)
{
printf("L");
}
}
else
{
for(int i=1;i<=cr-cl;i++)
{
printf("R");
}
}
if(cu>cd)
{
for(int i=1;i<=cu-cd;i++)
{
printf("U");
}
}
else
{
for(int i=1;i<=cd-cu;i++)
{
printf("D");
}
}
}
else
{
if(cu>cd)
{
for(int i=1;i<=cu-cd;i++)
{
printf("U");
}
}
else
{
for(int i=1;i<=cd-cu;i++)
{
printf("D");
}
}
if(cl>cr)
{
for(int i=1;i<=cl-cr;i++)
{
printf("L");
}
}
else
{
for(int i=1;i<=cr-cl;i++)
{
printf("R");
}
}
}
}
printf("\n");
}
signed main()
{
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3884kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
UDRLRLU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 20ms
memory: 3860kb
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 UDUUUUURR RLDDRRR UD Impossible RLRLDDLL UDRLRLDD Impossible UDUDRLDDL LL Impossible UDRLUUR Impossible Impossible Impossible RLRLRLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RLRLRLRRUU UDLLL Impossible UUULDDD UDUDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 31ms
memory: 3940kb
input:
11107 1 0 LLRLRURLR 1 0 LLRR 0 1 R 1 0 LLLRLRRR 1 0 RUL 0 1 UD 1 0 RLRLU 0 1 DDDUUUDU 1 0 RURRLLRLL 1 0 LRLR 1 0 ULR 0 1 R 0 1 DDUUUDR 0 1 UUDDUDDU 0 1 DDUUDU 1 0 RRLRLLRLRL 1 0 RLRRLL 1 0 LUR 1 0 U 1 0 LRRRLLLR 0 1 DRUUDDUDU 0 1 DUUDDUR 1 0 LRLRLR 0 1 UUDDDUDU 0 1 R 0 1 UDUDDU 0 1 DUUDUD 1 0 RRLRRR...
output:
LRLRLRLRU LRLR R LRLRLRLR LRU DU LRLRU DUDUDUDU LRLRLRLRU LRLR LRU R DUDUDUR DUDUDUDU DUDUDU LRLRLRLRLR LRLRLR LRU U LRLRLRLR DUDUDUDUR DUDUDUR LRLRLR DUDUDUDU R DUDUDU DUDUDU LRLRLRLRLR DUDUDUDU DUDU LRLRLRLRU DUDU LRLRLR LRU LRU U LRU LRLRLR LRLRLRLRLR U DUDUDU R LRLRLR DUDUDUDUR DUDUDUDUR LRLRLR ...
result:
ok 11107 cases