QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408751#6422. Evil CoordinateNelofusAC ✓22ms3904kbC++201.6kb2024-05-10 23:04:482024-05-10 23:04:49

Judging History

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

  • [2024-05-10 23:04:49]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:3904kb
  • [2024-05-10 23:04:48]
  • 提交

answer

// Narcissus & ?????????

#include <bits/stdc++.h>
using i64 = long long;

//{{{????
template<typename Ta, typename Tb>
inline void chkmax(Ta &a, const Tb &b) {if (a < b)	a = b;}
template<typename Ta, typename Tb>
inline void chkmin(Ta &a, const Tb &b) {if (a > b)	a = b;}
//}}}

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int cnt[4];
int p[4];

void solve() {
	int x, y;
	std::string s;
	std::cin >> x >> y;
	std::cin >> s;
	memset(cnt, 0, sizeof(cnt));
	for (const char &c : s) {
		if (c == 'L')
			cnt[0]++;
		if (c == 'U')
			cnt[1]++;
		if (c == 'R')
			cnt[2]++;
		if (c == 'D')
			cnt[3]++;
	}

	auto check = [&]() -> bool {
		int cx = 0, cy = 0;
		if (cx == x && cy == y) {
			return false;
		}

		for (int i = 0; i < 4; i++) {
			for (int t = 0; t < cnt[p[i]]; t++) {
				cx += dx[p[i]];
				cy += dy[p[i]];
				if (cx == x && cy == y)
					return false;
			}
		}
		return true;
	};


	for (int i = 0; i < 4; i++)	p[i] = i;
	int pcount = 4 * 3 * 2 * 1;
	while (pcount--) {
		if (check()) {
			for (int i = 0; i < 4; i++) {
				for (int t = 0; t < cnt[p[i]]; t++) {
					if (p[i] == 0)
						std::cout << "L";
					if (p[i] == 1)
						std::cout << "U";
					if (p[i] == 2)
						std::cout << "R";
					if (p[i] == 3)
						std::cout << "D";
				}
			}
			std::cout << '\n';
			return ;
		}
		std::next_permutation(p, p + 4);
	}
	std::cout << "Impossible" << '\n';
}

int main() {
#ifdef HeratinoNelofus
	freopen("input.txt", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int T;
	std::cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3588kb

input:

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

output:

LLUURRD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: 0
Accepted
time: 22ms
memory: 3904kb

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:

UURRDD
UUR
Impossible
Impossible
Impossible
UUUUUURRD
LRRRRDD
UD
Impossible
LLLLRRDD
LLURRDDD
Impossible
UULLDDDDR
LL
Impossible
LUUURRD
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
LR
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
LLLUD
Impossible
LUUUDDD
UURRDD
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 22ms
memory: 3812kb

input:

11107
1 0
LLRLRURLR
1 0
LLRR
0 1
R
1 0
LLLRLRRR
1 0
RUL
0 1
UD
1 0
RLRLU
0 1
DDDUUUDU
1 0
RURRLLRLL
1 0
LRLR
1 0
ULR
0 1
R
0 1
DDUUUDR
0 1
UUDDUDDU
0 1
DDUUDU
1 0
RRLRLLRLRL
1 0
RLRRLL
1 0
LUR
1 0
U
1 0
LRRRLLLR
0 1
DRUUDDUDU
0 1
DUUDDUR
1 0
LRLRLR
0 1
UUDDDUDU
0 1
R
0 1
UDUDDU
0 1
DUUDUD
1 0
RRLRRR...

output:

LLLLURRRR
LLRR
R
LLLLRRRR
LUR
DU
LLURR
DDDDUUUU
LLLLURRRR
LLRR
LUR
R
RUUUDDD
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
LUR
U
LLLLRRRR
RUUUUDDDD
RUUUDDD
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
LLLLURRRR
DDUU
LLLRRR
LUR
LUR
U
LUR
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RUUUUDDDD
RUUUUDDDD
LLLRRR
...

result:

ok 11107 cases