QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606619#6422. Evil CoordinateLJY_ljyWA 18ms4056kbC++114.2kb2024-10-03 11:01:532024-10-03 11:01:54

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 11:01:54]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:4056kb
  • [2024-10-03 11:01:53]
  • 提交

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