QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506639#6422. Evil Coordinate122WA 15ms3900kbC++142.0kb2024-08-05 20:22:542024-08-05 20:22:55

Judging History

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

  • [2024-08-05 20:22:55]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3900kb
  • [2024-08-05 20:22:54]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0); 
#define int long long
using namespace std;

signed main() {
    IOS;
    int t;
    cin >> t;
    while (t--) {
        int mx, my;
        cin >> mx >> my;
        string str;
        cin >> str;
        vector<int> cnt(4, 0);  // U, D, L, R
        for (char ch : str) {
            if (ch == 'U') cnt[0]++;
            else if (ch == 'D') cnt[1]++;
            else if (ch == 'L') cnt[2]++;
            else if (ch == 'R') cnt[3]++;
        }

        int up = cnt[0], down = cnt[1], left = cnt[2], right = cnt[3];

        // Calculate the potential range for x and y the robot can reach
        int min_x = -left, max_x = right;
        int min_y = -down, max_y = up;

        // Check if the mine is within the reachable range
        if (mx >= min_x && mx <= max_x && my >= min_y && my <= max_y) {
            // Calculate remaining moves needed to avoid the mine
            int rem_x = mx - min_x;  // Remaining x moves to reach the mine
            int rem_y = my - min_y;  // Remaining y moves to reach the mine

            if ((mx == 0 && my == 0) || 
                (rem_x >= 0 && rem_x <= right - left && rem_y >= 0 && rem_y <= up - down)) {
                cout << "Impossible" << endl;
            } else {
                // Construct a valid path avoiding the mine
                string result;
                result += string(up, 'U');
                result += string(down, 'D');
                result += string(left, 'L');
                result += string(right, 'R');
                cout << result << endl;
            }
        } else {
            // Construct a valid path avoiding the mine
            string result;
            result += string(up, 'U');
            result += string(down, 'D');
            result += string(left, 'L');
            result += string(right, 'R');
            cout << result << endl;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU

output:

UUDLLRR
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3900kb

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
Impossible
Impossible
UUUUDDDLLR
UUUUUUDRR
DDLRRRR
UD
Impossible
DDLLLLRR
UDDDLLRR
LRR
UUDDDDLLR
LL
UUDDDLLLRR
UUUDLRR
Impossible
Impossible
UDLRR
DDLLLLLRRR
ULLLLRRRR
LR
Impossible
Impossible
Impossible
Impossible
LLLLRRRRRR
UULLLRRRRR
UDLLL
Impossible
UUUDDDL
UUDDRR
LLLLRRR
UUDDLRR
UUUU...

result:

wrong answer case 5, participant's output goes through forbidden coordinate