QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506731#6422. Evil CoordinateUmokWA 7ms3780kbC++204.7kb2024-08-05 20:59:392024-08-05 20:59:41

Judging History

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

  • [2024-08-05 20:59:41]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3780kb
  • [2024-08-05 20:59:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
#define int long long
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
#define mod 10007
#define eps 1e-7
int l, r, d, u, a, b;
void solve()
{
    l = d = r = u = 0;
    string s, ans;
    cin >> a >> b;
    cin >> s;

    for (char c : s)
    {
        if (c == 'L')
            l++;
        else if (c == 'R')
            r++;
        else if (c == 'U')
            u++;
        else
            d++;
    }
    int x = r - l, y = u - d;
    if (x == a && y == b || a == 0 && b == 0)
    {
        cout << "Impossible" << endl;
        return;
    }

    if (x == a && a == 0)
    {
        if ((y >= b && b > 0) || (y <= b && b < 0))
        {
            cout << "Impossible" << endl;
            return;
        }
    }
    else if (b == y && b == 0)
    {
        if ((x >= a && a > 0) || (x <= a && a < 0))
        {
            cout << "Impossible" << endl;
            return;
        }
    }

    int mins = min(l, r);
    if (a == 1)
    {
        for (int i = 1; i <= mins; i++)
        {
            ans += "LR";
        }
    }
    else
    {
        for (int i = 1; i <= mins; i++)
            ans += "RL";
    }
    l -= mins, r -= mins;
    mins = min(u, d);
    if (b == 1)
    {
        for (int i = 1; i <= mins; i++)
            ans += "DU";
    }
    else
    {
        for (int i = 1; i <= mins; i++)
            ans += "UD";
    }
    u -= mins, d -= mins;

    if (a == 0 || b == 0)
    {
        if (a == 0)
        {
            if (b > 0 && u >= b && l == 0 && r == 0)
            {
                cout << "Impossible" << endl;
                return;
            }
            else if (b < 0 && -d <= b && l == 0 && r == 0)
            {
                cout << "Impossible" << endl;
                return;
            }
        }
        else if (b == 0)
        {
            if (a > 0 && r >= a && d == 0 && u == 0)
            {
                cout << "Impossible" << endl;
                return;
            }
            else if (a < 0 && -l <= a && d == 0 && u == 0)
            {
                cout << "Impossible" << endl;
                return;
            }
        }
    }

    // if (a == 0 || b == y)
    // {
    //     for (int i = 1; i <= l; i++)
    //         ans += "L";
    //     for (int i = 1; i <= r; i++)
    //         ans += "R";
    //     for (int i = 1; i <= u; i++)
    //         ans += "U";
    //     for (int i = 1; i <= d; i++)
    //         ans += "D";
    // }
    // else if (b == 0 || a == x)
    // {
    //     for (int i = 1; i <= u; i++)
    //         ans += "U";
    //     for (int i = 1; i <= d; i++)
    //         ans += "D";
    //     for (int i = 1; i <= l; i++)
    //         ans += "L";
    //     for (int i = 1; i <= r; i++)
    //         ans += "R";
    // }
    // else
    // {
    //     for (int i = 1; i <= u; i++)
    //         ans += "U";
    //     for (int i = 1; i <= d; i++)
    //         ans += "D";
    //     for (int i = 1; i <= l; i++)
    //         ans += "L";
    //     for (int i = 1; i <= r; i++)
    //         ans += "R";
    // }
    if (a)
    {
        for (int i = 1; r && i < a; i++)
            ans += "R", r--;
        for (int i = 1; l && -i > a; i++)
            ans += "L", l--;
        if (b != 0)
        {
            if (r > 1)
                for (int i = 1; r;)
                    ans += "R", r--;
            if (l > 1)
                for (int i = 1; l;)
                    ans += "L", l--;
        }
        if (-d < b && b < 0)
            for (; d; d--)
                ans += "D";
        else if (b < 0)
            for (int i = 1; -i > b; i++, d--)
                ans += "D";
        if (u > b && b > 0)
            for (; u; u--)
                ans += "U";
        else if (b > 0)
            for (int i = 1; i < b; i++, u--)
                ans += "U";

        for (int i = 1; i <= l; i++)
            ans += "L";
        for (int i = 1; i <= r; i++)
            ans += "R";
        for (int i = 1; i <= d; i++)
            ans += "D";
        for (int i = 1; i <= u; i++)
            ans += "U";
    }
    else
    {
        for (int i = 1; i <= l; i++)
            ans += "L";
        for (int i = 1; i <= r; i++)
            ans += "R";
        for (int i = 1; i <= d; i++)
            ans += "D";
        for (int i = 1; i <= u; i++)
            ans += "U";
    }

    cout << ans << endl;
}

signed main()
{
    IOS;
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

LRLRDUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 7ms
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:

UDUDRR
RUU
Impossible
Impossible
Impossible
UDRRUUUUU
RLRRRUUUDD
UD
Impossible
RLRLLLDD
RLRLUDDD
Impossible
RLUDUDLDD
LL
Impossible
LRUDUUUR
Impossible
Impossible
Impossible
RLRLRLLLDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
RLRLRLRRUU
UDLLLD
Impossible
UDUDUDL
UDUDRDDDD...

result:

wrong answer case 7, participant's output is not a permutation of the input