QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505920#6422. Evil CoordinatenaichakafeiWA 9ms3816kbC++202.2kb2024-08-05 13:37:402024-08-05 13:37:40

Judging History

This is the latest submission verdict.

  • [2024-08-05 13:37:40]
  • Judged
  • Verdict: WA
  • Time: 9ms
  • Memory: 3816kb
  • [2024-08-05 13:37:40]
  • Submitted

answer

/*
    /\_/\
   (= ._.)
   / >  \>
*/
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cassert>
#define int long long
#define double long double
using namespace std;
const int N = 1e6 + 10, M = 1e6 + 10, MOD = 1e9 + 7;
int a[N];
void solve() {
	int x, y;
	cin >> x >> y;
	string s;
	cin >> s;
	if (x == 0 && y == 0) {
		cout << "Impossible\n";
		return;
	}
	int t1 = 0, t2 = 0, t3 = 0, t4 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U') t1++;
		else if (s[i] == 'D') t2++;
		else if (s[i] == 'R') t3++;
		else t4++;
	}
	if (x == 0) {
		if (t3 == 0 && t4 == 0) {
			if (y > 0 && t1 - t2 >= y) {
				cout << "Impossible\n";
				return;
			}
			if (y < 0 && t1 - t2 <= y) {
				cout << "Impossible\n";
				return;
			}
		}
	}
	if (y == 0) {
		if (t1 == 0 && t2 == 0) {
			if (x > 0 && t3 - t4 >= x) {
				cout << "Impossible\n";
				return;
			}
			if (x < 0 && t3 - t4 <= x) {
				cout << "Impossible\n";
				return;
			}
		}
	}
	string ans;
	if (t1 - t2 == y && t3 - t4 == x) {
		cout << "Impossible\n";
		return;
	} else if (t1 - t2 == y || x == 0) { //先动x
		for (int i = 0; i < t3; i++) ans += 'R';
		for (int i = 0; i < t4; i++) ans += 'L';

		for (int i = 0; i < t1; i++) ans += 'U';
		for (int i = 0; i < t2; i++) ans += 'D';

	} else if (t3 - t4 == x || y == 0) { //先动y
		for (int i = 0; i < t1; i++) ans += 'U';
		for (int i = 0; i < t2; i++) ans += 'D';

		for (int i = 0; i < t3; i++) ans += 'R';
		for (int i = 0; i < t4; i++) ans += 'L';
	} else {
		for (int i = 0; i < t1; i++) ans += 'U';
		for (int i = 0; i < t2; i++) ans += 'D';
		for (int i = 0; i < t3; i++) ans += 'R';
		for (int i = 0; i < t4; i++) ans += 'L';
	}
	cout << ans << '\n';
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TT = 1;
	cin >> TT;
	while (TT--) {
		solve();
	}
	return 0;
}
/*
    /\_/\
   (= ._.)
   / >  \>

   3

   2 2
   2 3
   1 4

   6 5
   1 2 3 5 7 7
   1 3 3 4 10

   1 1
   7
   7

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

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: 9ms
memory: 3708kb

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:

RRUUDD
UUR
Impossible
Impossible
Impossible
RRUUUUUUD
DDRRRRL
UD
Impossible
RRLLLLDD
RRLLUDDD
Impossible
UUDDDDRLL
LL
Impossible
UUUDRRL
Impossible
Impossible
Impossible
RRRLLLLLDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
RRRRRLLLUU
UDLLL
Impossible
LUUUDDD
UUDDRR
Impossi...

result:

wrong answer case 56, participant's output goes through forbidden coordinate