QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505932 | #6422. Evil Coordinate | naichakafei | AC ✓ | 10ms | 3976kb | C++20 | 3.3kb | 2024-08-05 13:50:23 | 2024-08-05 13:50:23 |
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
if (y == 0) {
if (t1 != 0) {
ans += 'U';
t1--;
} else if (t2 != 0) {
ans += 'D';
t2--;
}
}
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';
}
} else if (t3 - t4 == x) { //先动y
if (x == 0) {
if (t3 != 0) {
ans += 'R';
t3--;
} else if (t4 != 0) {
ans += 'L';
t4--;
}
}
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';
}
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';
}
} else {
if (y == 0) {
if (t1 != 0) {
ans += 'U';
t1--;
} else if (t2 != 0) {
ans += 'D';
t2--;
}
}
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: 3748kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRDUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 10ms
memory: 3976kb
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 URU Impossible Impossible Impossible RRDUUUUUU RRRRLDD UD Impossible LLLLRRDD LLRRUDDD Impossible UUDDDDRLL LL Impossible DUUULRR Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU LLLUD Impossible ULUUDDD UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 10ms
memory: 3728kb
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:
ULLLLRRRR LLRR R LLLLRRRR ULR DU ULLRR DDDDUUUU ULLLLRRRR LLRR ULR R RDDDUUU DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR ULR U LLLLRRRR RDDDDUUUU RDDDUUU LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU ULLLLRRRR DDUU LLLRRR ULR ULR U ULR LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR RDDDDUUUU RDDDDUUUU LLLRRR ...
result:
ok 11107 cases