QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691602 | #6422. Evil Coordinate | yzj123# | AC ✓ | 23ms | 3728kb | C++20 | 4.8kb | 2024-10-31 12:11:26 | 2024-10-31 12:11:30 |
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 (x == 0 && y == 0) {
std::cout << t;
return ;
}
if (w[0] == 0 && w[1] == 0) {
if (x==0&&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 << 'U';
}
for (int i = 0; i < w[3]; i ++) {
std::cout << 'D';
}
std::cout << '\n';
}
}
return ;
} else if (w[2] == 0 && w[3] == 0) {
if (y==0&&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 (w[0]==w[1] ) {
if(x==0)
{
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';
for(int i=0;i<w[1];++i)std::cout<<'R';
std::cout<<'\n';
}
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';
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';
}
else if(x<0)
{
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';
}
return;
} else if (w[2] == w[3]) {
if(y==0)
{
for(int i=0;i<w[2];++i)std::cout<<'U';
for(int i=0;i<w[0];++i)std::cout<<'L';
for(int i=0;i<w[1];++i)std::cout<<'R';
for(int i=0;i<w[3];++i)std::cout<<'D';
std::cout<<'\n';
}
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';
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 if(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[0];++i)std::cout<<'L';
for(int i=0;i<w[1];++i)std::cout<<'R';
std::cout<<'\n';
}
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 23ms
memory: 3728kb
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 RRUUUUUUD RRRRLDD UD Impossible RRLLLLDD LLRRUDDD Impossible UUDDDDRLL LL Impossible UUUDRRL Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU UDLLL Impossible UUULDDD UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 23ms
memory: 3660kb
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:
LLLLRRRRU LLRR R LLLLRRRR LRU DU LLRRU DDDDUUUU LLLLRRRRU LLRR LRU R DDDUUUR DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR LRU U LLLLRRRR DDDDUUUUR DDDUUUR LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU LLLLRRRRU DDUU LLLRRR LRU LRU U LRU LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR DDDDUUUUR DDDDUUUUR LLLRRR ...
result:
ok 11107 cases