QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691425 | #6422. Evil Coordinate | yzj123# | WA | 12ms | 4060kb | C++20 | 3.0kb | 2024-10-31 11:25:28 | 2024-10-31 11:25:28 |
Judging History
answer
#include<bits/stdc++.h>
using i64 = long long;
const int inf = 2e9;
void solve() {
int x, y;
std::cin >> x >> y;
std::string s, t = "Impossible\n";
std::cin >> s;
int a = 0, b = 0;
std::vector<int> w(4);
for (auto c : s) {
if (c == 'L') w[0] ++;
if (c == 'R') w[1] ++;
if (c == 'U') w[2] ++;
if (c == 'D') w[3] ++;
}
b = (w[2] - w[3]), a = (w[1] - w[0]);
if (w[0] == 0 && w[1] == 0) {
if (y >= std::min(0, b) && y <= std::max(0, b)) {
std::cout << t;
} else {
if (y > 0) {
for (int i = 0; i < w[3]; i ++) {
std::cout << 'D';
}
for (int i = 0; i < w[2]; i ++) {
std::cout << 'U';
}
std::cout << '\n';
} else {
for (int i = 0; i < w[2]; i ++) {
std::cout << 'D';
}
for (int i = 0; i < w[3]; i ++) {
std::cout << 'U';
}
std::cout << '\n';
}
}
return ;
} else if (w[2] == 0 && w[3] == 0) {
if (x >= std::min(0, a) && x <= std::max(0, a)) {
std::cout << t;
} else {
if (x > 0) {
for (int i = 0; i < w[0]; i ++) {
std::cout << 'L';
}
for (int i = 0; i < w[1]; i ++) {
std::cout << 'R';
}
std::cout << '\n';
} else {
for (int i = 0; i < w[1]; i ++) {
std::cout << 'R';
}
for (int i = 0; i < w[0]; i ++) {
std::cout << 'L';
}
std::cout << '\n';
}
}
return ;
}
if (x == a && y == b) {
std::cout << t;
return ;
}
if (x == a || y == 0) {
for (int i = 0; i < w[2]; i ++) {
std::cout << 'U';
}
for (int i = 0; i < w[3]; i ++) {
std::cout << 'D';
}
for (int i = 0; i < w[1]; i ++) {
std::cout << 'R';
}
for (int i = 0; i < w[0]; i ++) {
std::cout << 'L';
}
std::cout << '\n';
} else {
for (int i = 0; i < w[1]; i ++) {
std::cout << 'R';
}
for (int i = 0; i < w[0]; i ++) {
std::cout << 'L';
}
for (int i = 0; i < w[2]; i ++) {
std::cout << 'U';
}
for (int i = 0; i < w[3]; i ++) {
std::cout << 'D';
}
std::cout << '\n';
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t --) {
solve();
}
return 0;
}
/*
5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
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: 12ms
memory: 4060kb
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:
UUDDRR UUR UUDR Impossible Impossible RRUUUUUUD RRRRLDD Impossible Impossible RRLLLLDD RRLLUDDD Impossible UUDDDDRLL LL Impossible UUUDRRL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible UUDDDDRRRL UUDL Impossible RRRRRLLLUU LLLUD Impossible UUUDDDL UUDDRR Impossible ...
result:
wrong answer case 3, participant's output goes through forbidden coordinate