QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506445#6422. Evil CoordinateGrunrayWA 13ms3780kbC++205.8kb2024-08-05 17:30:152024-08-05 17:30:17

Judging History

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

  • [2024-08-05 17:30:17]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3780kb
  • [2024-08-05 17:30:15]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#define itn int
#define PII pair<int, int>
#define PLI pair<long long, int>
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#include<bits/stdc++.h>
#include<unordered_map>
using ll = long long;
using ldou = long double;
using unll = unsigned long long;
using namespace std;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) { f = ch != '-'; ch = getchar(); }
	while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	return f ? x : -x;
}

ll gcd(ll a, ll b) { // 最大公约数
	while (b ^= a ^= b ^= a %= b)
		;
	return a;
}
ll lcm(ll a, ll b) { // 最小公倍数
	return a / gcd(a, b) * b;
}
ll qmi(ll m, ll k, ll p) { // 快速幂
	//求 m^k mod p,时间复杂度 O(logk)。
	//m为底数,k为幂
	ll res = 1 % p, t = m;
	while (k) {
		if (k & 1) res = res * t % p;
		t = t * t % p;
		k >>= 1;
	}
	return res;
}
unll qmi(unll m, unll k, unll p) { //龟速乘
	ll res = 0, t = m;
	while (k) {
		if (k & 1) res = (res + t) % p;
		k >>= 1;
		t = (t << 1) % p;
	}
	return res;
}

////////////////////////////////////////////////////////////////////////////////

ll n, m, k;
const int N = 1000010;
const int M = 2e5 + 50;
const ll INF = 0x3f3f3f3f;
const ll MODE = ll(998244353);
const double Pi = 3.1415926;
const double eps = 1e-8;
const int dx[4] = { 1,-1, 0, 0 };
const int dy[4] = { 0, 0, 1,-1 };
//priority_queue<int> p;//这是一个大根堆q
//priority_queue<int, vector<int>, greater<int> >q;//这是一个小根堆q
//priority_queue<ll, vector<ll>, greater<ll> >pq; // 小根

ll a[5];
string str;

void solve() {

	ll edx = 0, edy = 0;
	ll x, y;
	cin >> x >> y;
	
	cin >> str;
	memset(a, 0, sizeof(a));
	if (x == 0 && y == 0) {
		cout << "Impossible" << '\n';
		return;
	}

	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == 'U') a[0]++;
		if (str[i] == 'D') a[1]++;
		if (str[i] == 'L') a[2]++;
		if (str[i] == 'R') a[3]++;
	}

	edx = a[3] - a[2];
	edy = a[0] - a[1];

	if (edy == y && edx == x) {
		cout << "Impossible" << '\n';
		return;
	}
	
	if ((a[2] == 0 && a[3] == 0))
	{
		if (x != 0) {
			cout << str << '\n';
			return;
		}
		else if (y > edy && y >= 0) {
			for (int i = 0; i < a[1]; i++)cout << 'D';
			for (int i = 0; i < a[0]; i++)cout << 'U';
			cout << '\n';
			return;
		}
		else if (y <= 0 && edy <= y)
		{
			cout << "Impossible" << '\n';
			return;
		}
		else if (edy >= 0 && edy >= y && y >= 0)
		{
			cout << "Impossible" << '\n';
			return;
		}
		else if (edy >= 0 && edy >= y)
		{
			for (int i = 1; i <= a[0]; i++) cout << 'U';
			for (int i = 1; i <= a[1]; i++) cout << 'D';
			cout << '\n';
			return;
		}
		else if (y < edy && edy <= 0) {
			for (int i = 1; i <= a[0]; i++) cout << 'U';
			for (int i = 1; i <= a[1]; i++) cout << 'D';
			cout << '\n';
			return;
		}
		else {
			cout << "Impossible" << '\n';
			return;
		}
		
	}
	else if (a[0] == 0 && a[1] == 0)
	{
		if (y) {
			cout << str << '\n';
			return;
		}
		else if (x <= 0 && edx <= x)
		{
			cout << "Impossible" << '\n';
			return;
		}
		else if (edx >= 0 && edx >= x && x >= 0) {
			cout << "Impossible" << '\n';
			return;
		}
		else if (x > edx && x >= 0) {
			for (int i = 1; i <= a[2]; i++) cout << 'L';
			for (int i = 1; i <= a[3]; i++) cout << 'R';
			cout << '\n';
		}
		else if (edx >= 0 && edx >= x)
		{
			for (int i = 1; i <= a[3]; i++) cout << 'R';
			for (int i = 1; i <= a[2]; i++) cout << 'L';
			cout << '\n';
			return;
		}
		else if (edx <= 0 && edx > x) {
			for (int i = 1; i <= a[3]; i++) cout << 'R';
			for (int i = 1; i <= a[2]; i++) cout << 'L';
			cout << '\n';
			return;
		}
		else {
			cout << "Impossible" << '\n';
			return;
		}
	}

	if (edy == y)
	{
		if (y == 0)
		{
			if (a[0] != 0) {
				cout << 'U';
				--a[0];
			}
			else if (a[1] != 0) {
				cout << 'D';
				--a[1];
			}
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			cout << '\n';
			return;
		}
		else
		{
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			cout << '\n';
			return;
		}
	}
	else if (edx == x)
	{
		if (x == 0) {
			if (a[2] != 0) {
				cout << 'L';
				--a[2];
			}
			else if (a[3] != 0) {
				cout << 'R';
				--a[3];
			}
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			cout << '\n';
			return;
		}
		else {
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			cout << '\n';
			return;
		}
		
	}
	else
	{
		if (x == 0) {
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			cout << '\n';
			return;
		}
		else {
			for (int i = 0; i < a[0]; i++) cout << "U";
			for (int i = 0; i < a[1]; i++) cout << "D";
			for (int i = 0; i < a[2]; i++) cout << "L";
			for (int i = 0; i < a[3]; i++) cout << "R";
			cout << '\n';
			return;
		}
		
	}

}
signed main() {
	std::ios::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0);
	/*freopen("out.txt", "r", stdin);
	freopen("wrt.txt", "w", stdout);*/
	int TTT = 1; cin >> TTT;
	while (TTT--) {
		solve();
	}
	/*while (cin >> n >> m) {
		solve();
	}*/

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

LLRRUUD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 3780kb

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:

URRUDD
UUR
Impossible
Impossible
Impossible
RRUUUUUUD
DDLRRRR
UD
Impossible
LLLLRRDD
LLRRUDDD
Impossible
UUDDDDLLR
LL
Impossible
UUUDLRR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
ULUUDDD
UUDDRR
Impossi...

result:

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