QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#505993 | #6422. Evil Coordinate | Dreamy_Blaze | TL | 0ms | 3996kb | C++14 | 4.4kb | 2024-08-05 14:29:37 | 2024-08-05 14:29:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
char c;
cin>>n;
while(n--){
map<char,int> maaa1;
maaa1['R']=0,maaa1['L']=0,maaa1['U']=0,maaa1['D']=0;
scanf("%d%d",&x,&y);
getchar();
while(scanf("%c",&c)==1&&c!='\n'){
maaa1[c]++; //DLRU
}
//for(auto i:maaa1)cout<<i.second<<endl;
if((maaa1['R']-maaa1['L']==x&&maaa1['U']-maaa1['D']==y)||(x==0&&y==0))printf("Impossible\n");
else if(x==0&&maaa1['R']==0&&maaa1['L']==0&&abs(maaa1['U']-maaa1['D'])>=abs(y))printf("Impossible\n");
else if(y==0&&maaa1['U']==0&&maaa1['D']==0&&abs(maaa1['R']-maaa1['L'])>=abs(x))printf("Impossible\n");
else if(x==0){
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
if(y>0){
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
} else {
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
}
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
printf("\n");
}
else if(y==0){
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
if(x>0){
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
} else {
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
}
while(maaa1['D']>0){
printf("D");
maaa1['d']--;
}
printf("\n");
}
else if(x>0&&y>0){
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
printf("\n");
}
else if(x>0&&y<0){
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
printf("\n");
}
else if(x<0&&y>0){
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
printf("\n");
}
else if(x<0&&y<0){
while(maaa1['R']>0){
printf("R");
maaa1['R']--;
}
while(maaa1['D']>0){
printf("D");
maaa1['D']--;
}
while(maaa1['L']>0){
printf("L");
maaa1['L']--;
}
while(maaa1['U']>0){
printf("U");
maaa1['U']--;
}
printf("\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3996kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLUURRD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Time Limit Exceeded
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:
UURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...