QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506343#6422. Evil CoordinatebuzhijingdiWA 16ms3836kbC++144.2kb2024-08-05 16:50:522024-08-05 16:50:52

Judging History

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

  • [2024-08-05 16:50:52]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3836kb
  • [2024-08-05 16:50:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 1e6 + 5;
map<char, int> mp, mp2;
string s;
char ans[maxn];
int cnt;


void solve()
{
	int x, y, ansx = 0, ansy = 0;
	cin >> x >> y;
	cin >> s;
	mp.clear();

	if (x == 0 && y == 0) {
		cout << "Impossible" << endl;
		return;
	}
	int flag = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U') {
			ansy++;
		}
		if (s[i] == 'D') {
			ansy--;
		}
		if (s[i] == 'L') {
			ansx--;
		}
		if (s[i] == 'R') {
			ansx++;
		}
		if (ansx == x && ansy == y) {
			flag = 1;
		}
	}
//cout << ansx << " " << ansy << endl;
	if ((x != ansx || y != ansy)&&flag != 1) {
		cout << s << endl;
		return;
	}
	for (int i = 0; i < s.size(); i++) {
		mp[s[i]]++;
	}

	if ((mp['U'] == 0 && mp['D'] == 0)) {
		if (x >= 0) {
			if (mp['L'] > mp['R']) {  //先左后右
				for (int i = 1; i <= mp['L']; i++) {
					cout << "L";
				}
				for (int i = 1; i <= mp['R']; i++) {
					cout << "R";
				}
				cout << endl;
				return;
			}
			else if (mp['L'] == mp['R']) {
				cout << "Impossible" << endl;
				return;
			}
			else {
				if (mp['R'] - mp['L'] >= x) {
					cout << "Impossible" << endl;
					return;
				}
				else { // 先左
					for (int i = 1; i <= mp['L']; i++) {
						cout << "L";
					}
					for (int i = 1; i <= mp['R']; i++) {
						cout << "R";
					}
					cout << endl;
					return;
				}
			}
		}
		else {
			if (mp['L'] <= mp['R']) {  //先右
				for (int i = 1; i <= mp['R']; i++) {
					cout << "R";
				}
				for (int i = 1; i <= mp['L']; i++) {
					cout << "L";
				}
				cout << endl;
				return;
			}
			else {
				if (mp['R'] - mp['L'] <= x) {
					cout << "Impossible" << endl;
					return;
				}
				else { // 先右
					for (int i = 1; i <= mp['R']; i++) {
						cout << "R";
					}
					for (int i = 1; i <= mp['L']; i++) {
						cout << "L";
					}
					cout << endl;
					return;
				}
			}
		}

	}


	if ((mp['L'] == 0 && mp['R'] == 0)) {
		if (y >= 0) {
			if (mp['D'] > mp['U']) {  //先左后右
				for (int i = 1; i <= mp['D']; i++) {
					cout << "D";
				}
				for (int i = 1; i <= mp['U']; i++) {
					cout << "U";
				}
				cout << endl;
				return;
			}
			else if (mp['D'] == mp['U']) {
				cout << "Impossible" << endl;
				return;
			}
			else {
				if (mp['U'] - mp['D'] >= y) {
					cout << "Impossible" << endl;
					return;
				}
				else { // 先左
					for (int i = 1; i <= mp['D']; i++) {
						cout << "D";
					}
					for (int i = 1; i <= mp['U']; i++) {
						cout << "U";
					}
					cout << endl;
					return;
				}
			}
		}
		else {
			if (mp['D'] <= mp['U']) {  //先右
				for (int i = 1; i <= mp['U']; i++) {
					cout << "U";
				}
				for (int i = 1; i <= mp['D']; i++) {
					cout << "D";
				}
				cout << endl;
				return;
			}
			else {
				if (mp['U'] - mp['D'] <= y) {
					cout << "Impossible" << endl;
					return;
				}
				else { // 先右
					for (int i = 1; i <= mp['U']; i++) {
						cout << "U";
					}
					for (int i = 1; i <= mp['D']; i++) {
						cout << "D";
					}
					cout << endl;
					return;
				}
			}
		}

	}


	cnt = 0;

	int dx = 0, dy = 0;
	dy += mp['U'];
	dy -= mp['D'];
	dx += mp['R'];
	dx -= mp['L'];
	if (dx == x && dy == y) {
		cout << "Impossible" << endl;
		return;
	}

	if (x >= 0) {
		for (int i = 1; i <= mp['L']; i++) {
			ans[++cnt] = 'L';
		}
	}
	else {
		for (int i = 1; i <= mp['R']; i++) {
			ans[++cnt] = 'R';
		}
	}
	if (y >= 0) {
		for (int i = 1; i <= mp['D']; i++) {
			ans[++cnt] = 'D';
		}
	}
	else {
		for (int i = 1; i <= mp['U']; i++) {
			ans[++cnt] = 'U';
		}
	}

	if (x >= 0) {
		for (int i = 1; i <= mp['R']; i++) {
			ans[++cnt] = 'R';
		}
	}
	else {
		for (int i = 1; i <= mp['L']; i++) {
			ans[++cnt] = 'L';
		}
	}
	if (y >= 0) {
		for (int i = 1; i <= mp['U']; i++) {
			ans[++cnt] = 'U';
		}
	}
	else {
		for (int i = 1; i <= mp['D']; i++) {
			ans[++cnt] = 'D';
		}
	}

	for (int i = 1; i <= cnt; i++) {
		cout << ans[i];
	}
	cout << endl;

}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

LLDRRUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 3836kb

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:

RUDUDR
URU
Impossible
Impossible
Impossible
RRUUUDUUU
RRDRLDR
UD
Impossible
LDDLLLRR
LDRURLDD
Impossible
DUDDLLRDU
LL
Impossible
URDULUR
Impossible
Impossible
Impossible
LDLRLLDRRL
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LRURRLLRRU
LLUDL
Impossible
UUDDDLU
RURUDD
Impossi...

result:

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