QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505930#6422. Evil CoordinatenaichakafeiWA 0ms3780kbC++203.2kb2024-08-05 13:48:452024-08-05 13:48:45

Judging History

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

  • [2024-08-05 13:48:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-08-05 13:48:45]
  • 提交

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
		if (y == 0) {
			if (t1 != 0) {
				ans += 'U';
				t1--;
			} else {
				ans += 'D';
				t2--;
			}
		}
		if (x > 0) {
			for (int i = 0; i < t4; i++) ans += 'L';
			for (int i = 0; i < t3; i++) ans += 'R';
		} else {
			for (int i = 0; i < t3; i++) ans += 'R';
			for (int i = 0; i < t4; i++) ans += 'L';
		}
		if (y > 0) {
			for (int i = 0; i < t2; i++) ans += 'D';
			for (int i = 0; i < t1; i++) ans += 'U';
		} else {
			for (int i = 0; i < t1; i++) ans += 'U';
			for (int i = 0; i < t2; i++) ans += 'D';
		}

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

		if (x > 0) {
			for (int i = 0; i < t4; i++) ans += 'L';
			for (int i = 0; i < t3; i++) ans += 'R';
		} else {
			for (int i = 0; i < t3; i++) ans += 'R';
			for (int i = 0; i < t4; i++) ans += 'L';
		}
	} else {
		if (y == 0) {
			if (t1 != 0) {
				ans += 'U';
				t1--;
			} else {
				ans += 'D';
				t2--;
			}
		}
		if (x > 0) {
			for (int i = 0; i < t4; i++) ans += 'L';
			for (int i = 0; i < t3; i++) ans += 'R';
		} else {
			for (int i = 0; i < t3; i++) ans += 'R';
			for (int i = 0; i < t4; i++) ans += 'L';
		}

		if (y > 0) {
			for (int i = 0; i < t2; i++) ans += 'D';
			for (int i = 0; i < t1; i++) ans += 'U';
		} else {
			for (int i = 0; i < t1; i++) ans += 'U';
			for (int i = 0; i < t2; i++) ans += 'D';
		}
	}
	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

*/

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

input:

5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU

output:

LLRRDUU
LUUU
Impossible
Impossible
Impossible

result:

wrong answer case 2, participant's output is not a permutation of the input