QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606619 | #6422. Evil Coordinate | LJY_ljy | WA | 18ms | 4056kb | C++11 | 4.2kb | 2024-10-03 11:01:53 | 2024-10-03 11:01:54 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
const int MAXN = 1e5 + 10;
char str[MAXN];
int mx, my;
bool used[MAXN];
int main() {
int t; scanf("%d", &t);
for (int u = 1; u <= t; u++) {
scanf("%d %d", &mx, &my);
scanf("%s", str + 1);
bool flag = true;
int n = strlen(str + 1);
for (int i = 1; i <= n; i++) used[i] = false;
for (int i = 1; i <= n; i++) {
if (str[i] != 'U' && str[i] != 'D') {
flag = false;
break;
}
}
if (flag) { //UD
if (mx != 0) printf("%s\n", str + 1);
else {
int End = 0;
for (int i = 1; i <= n; i++) {
if (str[i] == 'U') End++;
else End--;
}
if (my > 0) {
if (End >= my) printf("Impossible\n");
else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'D') printf("D");
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'U') printf("U");
}
printf("\n");
}
} else if (my < 0) {
if (End <= my) printf("Impossible\n");
else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'U') printf("U");
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'D') printf("D");
}
printf("\n");
}
} else
printf("Impossible\n");
}
} else {
flag = true;
for (int i = 1; i <= n; i++) {
if (str[i] != 'L' && str[i] != 'R') {
flag = false;
break;
}
}
if (flag) { //LR
if (my != 0) printf("%s\n", str + 1);
else {
int End = 0;
for (int i = 1; i <= n; i++) {
if (str[i] == 'L') End--;
else End++;
}
if (mx < 0) {
if (End <= mx) printf("Impossible\n");
else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'R') printf("R");
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'L') printf("L");
}
printf("\n");
}
} else if (mx > 0) {
if (End >= mx) printf("Impossible\n");
else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'L') printf("L");
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'R') printf("R");
}
printf("\n");
}
} else
printf("Impossible\n");
}
} else {
int End1 = 0, End2 = 0;
for (int i = 1; i <= n; i++) {
if (str[i] == 'U') End1++;
if (str[i] == 'D') End1--;
if (str[i] == 'L') End2--;
if (str[i] == 'R') End2++;
}
if (my == End1 && mx == End2) printf("Impossible\n");
else if (mx == 0 && my == 0) printf("Impossible\n");
else {
if (my != End1) {
if (mx != 0) {
for (int i = 1; i <= n; i++) {
if (str[i] == 'U' || str[i] == 'D')
printf("%c", str[i]);
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'L' || str[i] == 'R')
printf("%c", str[i]);
}
printf("\n");
} else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'L' || str[i] == 'R') {
printf("%c", str[i]);
used[i] = true;
break;
}
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'U' || str[i] == 'D')
printf("%c", str[i]);
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'L' || str[i] == 'R')
if (!used[i])
printf("%c", str[i]);
}
}
} else {
if (my != 0) {
for (int i = 1; i <= n; i++) {
if (str[i] == 'L' || str[i] == 'R')
printf("%c", str[i]);
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'U' || str[i] == 'D')
printf("%c", str[i]);
}
printf("\n");
} else {
for (int i = 1; i <= n; i++) {
if (str[i] == 'U' || str[i] == 'D') {
printf("%c", str[i]);
used[i] = true;
break;
}
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'L' || str[i] == 'R')
printf("%c", str[i]);
}
for (int i = 1; i <= n; i++) {
if (str[i] == 'U' || str[i] == 'D')
if (!used[i])
printf("%c", str[i]);
}
printf("\n");
}
}
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
RRLLUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 4056kb
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:
URRDUD UUR Impossible Impossible Impossible RRUUUDUUU DDRRRLR UD Impossible LLLLRRDD LRRLDUDD Impossible DUDDDULLR LL Impossible UDUURLR Impossible Impossible Impossible LLRLLRRLDD Impossible RL Impossible Impossible Impossible Impossible Impossible LRRRLLRRUU UDLLL Impossible ULUDDDU UUDDRR Impossi...
result:
wrong answer case 35, participant's output is not a permutation of the input