QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505925 | #6422. Evil Coordinate | naichakafei | WA | 10ms | 3764kb | C++20 | 2.4kb | 2024-08-05 13:41:52 | 2024-08-05 13:41:52 |
Judging History
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
for (int i = 0; i < t3; i++) ans += 'R';
for (int i = 0; i < t4; i++) ans += 'L';
for (int i = 0; i < t1; i++) ans += 'U';
for (int i = 0; i < t2; i++) ans += 'D';
} else if (t3 - t4 == x) { //先动y
for (int i = 0; i < t1; i++) ans += 'U';
for (int i = 0; i < t2; i++) ans += 'D';
for (int i = 0; i < t3; i++) ans += 'R';
for (int i = 0; i < t4; i++) ans += 'L';
} else {
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: 100
Accepted
time: 0ms
memory: 3584kb
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: 10ms
memory: 3764kb
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:
RRUUDD RUU Impossible Impossible Impossible RRUUUUUUD RRRRLDD UD Impossible RRLLLLDD RRLLUDDD Impossible UUDDDDRLL LL Impossible UUUDRRL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU LLLUD Impossible LUUUDDD UUDDRR Impossi...
result:
wrong answer case 56, participant's output goes through forbidden coordinate