QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#231643 | #6422. Evil Coordinate | veg# | AC ✓ | 6ms | 3900kb | C++14 | 3.7kb | 2023-10-29 15:02:26 | 2023-10-29 15:02:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];
int L,R,U,D;
bool in(int x,int y,int z) {
return x>=y&&x<=z||x>=z&&x<=y;
}
void LRUD() {
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=R;++i) {
putchar('R');
}
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=D;++i) {
putchar('D');
}
puts("");
}
void UDLR() {
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=D;++i) {
putchar('D');
}
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=R;++i) {
putchar('R');
}
puts("");
}
void RLUD() {
for(int i=1;i<=R;++i) {
putchar('R');
}
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=D;++i) {
putchar('D');
}
puts("");
}
void DULR() {
for(int i=1;i<=D;++i) {
putchar('D');
}
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=R;++i) {
putchar('R');
}
puts("");
}
int main() {
int T; scanf("%d",&T);
while(T--) {
int mx,my; scanf("%d%d",&mx,&my);
scanf("%s",s+1);
int n=strlen(s+1);
L=0,R=0,U=0,D=0;
for(int i=1;i<=n;++i) {
L+=(s[i]=='L');
R+=(s[i]=='R');
U+=(s[i]=='U');
D+=(s[i]=='D');
}
int sx=R-L,sy=U-D;
if(mx==0&&my==0||mx==sx&&my==sy) {
puts("Impossible");
continue;
}
if(sx!=0&&sy!=0) {
if(mx!=sx&&my!=0) {
LRUD();
continue;
} else {
UDLR();
continue;
}
} else if(sx==0&&sy==0) {
if(my==0&&mx>0) {
LRUD();
continue;
} else if(mx<0&&my==0) {
RLUD();
continue;
} else if(mx==0&&my<0) {
UDLR();
continue;
} else {
DULR();
continue;
}
} else if(sx==0) {
if(mx==0&&in(my,0,sy)&&L==0) {
puts("Impossible");
continue;
} else if(mx>0) {
LRUD();
continue;
} else if(mx<0) {
RLUD();
continue;
} else if(!in(my,0,sy)) {
for(int i=1;i<=R;++i) {
putchar('R');
}
for(int i=1;i<=L;++i) {
putchar('L');
}
if(sy>0) {
for(int i=1;i<=D;++i) {
putchar('U');
putchar('D');
}
for(int i=D+1;i<=U;++i) {
putchar('U');
}
} else {
for(int i=1;i<=U;++i) {
putchar('D');
putchar('U');
}
for(int i=U+1;i<=D;++i) {
putchar('D');
}
}
puts("");
continue;
} else{
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=D;++i) {
putchar('D');
}
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=R;++i) {
putchar('R');
}
puts("");
continue;
}
} else {
if(my==0&&in(mx,0,sx)&&D==0) {
puts("Impossible");
continue;
} else if(my>0) {
DULR();
continue;
} else if(my<0) {
UDLR();
continue;
} else if(!in(mx,0,sx)) {
for(int i=1;i<=U;++i) {
putchar('U');
}
for(int i=1;i<=D;++i) {
putchar('D');
}
if(sx>0) {
for(int i=1;i<=L;++i) {
putchar('R');
putchar('L');
}
for(int i=L+1;i<=R;++i) {
putchar('R');
}
} else {
for(int i=1;i<=R;++i) {
putchar('L');
putchar('R');
}
for(int i=R+1;i<=L;++i) {
putchar('L');
}
}
puts("");
continue;
} else{
for(int i=1;i<=D;++i) {
putchar('D');
}
for(int i=1;i<=L;++i) {
putchar('L');
}
for(int i=1;i<=R;++i) {
putchar('R');
}
for(int i=1;i<=U;++i) {
putchar('U');
}
puts("");continue;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 6ms
memory: 3720kb
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:
UUDDRR UUR Impossible Impossible Impossible RRUUUUUUD LRRRRDD UD Impossible LLLLRRDD LLRRUDDD Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 6ms
memory: 3900kb
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:
LLLLRRRRU LLRR R LLLLRRRR LRU DU LLRRU DDDDUUUU LLLLRRRRU LLRR LRU R DDDUUUR DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR LRU U LLLLRRRR DDDDUUUUR DDDUUUR LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU LLLLRRRRU DDUU LLLRRR LRU LRU U LRU LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR DDDDUUUUR DDDDUUUUR LLLRRR ...
result:
ok 11107 cases