QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691444#6422. Evil Coordinateyzj123#WA 12ms3780kbC++203.0kb2024-10-31 11:29:202024-10-31 11:29:21

Judging History

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

  • [2024-10-31 11:29:21]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3780kb
  • [2024-10-31 11:29:20]
  • 提交

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 << '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 (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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
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: 3780kb

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