QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682368#6422. Evil CoordinateBlizzardWA 10ms3756kbC++147.5kb2024-10-27 15:11:132024-10-27 15:11:13

Judging History

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

  • [2024-10-27 15:11:13]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3756kb
  • [2024-10-27 15:11:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

//--------------------------------
// #define int long long
#define LL long long
// #define lc p << 1
// #define rc p << 1 | 1
#define lowbit(x) x & (-x)
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
// #pragma GCC optimize(2)
#define Blizzard ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"

//-----------------------------------------
int x, y;
int cnt[4];
void solve()
{

    cin >> x >> y;
    int nowx = 0, nowy = 0;
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
    string s;
    cin >> s;
    int visstep = -1;
    int finalx = 0, finaly = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'U')
        {
            cnt[0]++;
            nowy++;
        }
        if (s[i] == 'D')
        {
            cnt[1]++;
            nowy--;
        }
        if (s[i] == 'L')
        {
            cnt[2]++;
            nowx--;
        }
        if (s[i] == 'R')
        {
            cnt[3]++;
            nowx++;
        }

        if (nowx == x && nowy == y)
        {
            visstep = i + 1;
        }
    }

    finalx = nowx, finaly = nowy;
    string ans;

    if ((finalx == x && finaly == y) || (x == 0 && y == 0))
    {
        cout << "Impossible\n";
        return;
    }

    if (visstep == -1)
    {
        cout << s << '\n';
        return;
    }

    if ((cnt[1] == 0 && cnt[0] == 0) || (cnt[2] == 0 && cnt[3] == 0))
    {
        if ((cnt[1] == 0 && cnt[0] == 0))
        {
            if (x < 0)
            {
                if (cnt[3] - cnt[2] <= x)
                {

                    cout << "Impossible\n";
                    return;
                }
                while (cnt[3])
                {
                    ans.push_back(3);
                    cnt[3]--;
                }
                while (cnt[2])
                {
                    cnt[2]--;
                    ans.push_back(2);
                }
                for (int i = 0; i < ans.size(); i++)
                {
                    if (ans[i] == 0)
                        cout << 'U';
                    if (ans[i] == 1)
                        cout << 'D';
                    if (ans[i] == 2)
                        cout << 'L';
                    if (ans[i] == 3)
                        cout << 'R';
                }
                cout << '\n';
                return;
            }
            else
            {
                if (-1 * cnt[2] + cnt[3] >= x)
                {
                    cout << "Impossible\n";
                    return;
                }

                while (cnt[2])
                {
                    cnt[2]--;
                    ans.push_back(2);
                }
                while (cnt[3])
                {
                    ans.push_back(3);
                    cnt[3]--;
                }
                for (int i = 0; i < ans.size(); i++)
                {
                    if (ans[i] == 0)
                        cout << 'U';
                    if (ans[i] == 1)
                        cout << 'D';
                    if (ans[i] == 2)
                        cout << 'L';
                    if (ans[i] == 3)
                        cout << 'R';
                }
                cout << '\n';
                return;
            }
        }
        else if ((cnt[2] == 0 && cnt[3] == 0))
        {
            if (y > 0)
            {
                if (-1 * cnt[1] + cnt[0] >= y)
                {
                    cout << "Impossible\n";
                    return;
                }
                while (cnt[1])
                {
                    cnt[1]--;
                    ans.push_back(1);
                }
                while (cnt[0])
                {
                    ans.push_back(0);
                    cnt[0]--;
                }
            }
            else
            {
                if (cnt[0] - cnt[1] <= y)
                {
                    cout << "Impossible\n";
                    return;
                }
                while (cnt[0])
                {
                    cnt[0]--;
                    ans.push_back(0);
                }
                while (cnt[1])
                {
                    ans.push_back(1);
                    cnt[1]--;
                }
            }
            for (int i = 0; i < ans.size(); i++)
            {
                if (ans[i] == 0)
                    cout << 'U';
                if (ans[i] == 1)
                    cout << 'D';
                if (ans[i] == 2)
                    cout << 'L';
                if (ans[i] == 3)
                    cout << 'R';
            }
            cout << '\n';
            return;
        }
        cout << "Impossible\n";
        return;
    }
    nowx = nowy = 0;
    if (((x == 1 || x == -1) && (y == 0)) || ((y == 1 || y == -1) && (x == 0)))
    {
        if ((x == 1 || x == -1) && (y == 0))
        {

            if (cnt[0])
            {
                cnt[0]--;
                ans.push_back(0);
                nowy = 1;
            }
            else
            {
                cnt[1]--;
                ans.push_back(1);
                nowy = -1;
            }
        }
        else
        {

            if (cnt[3])
            {
                ans.push_back(3);
                cnt[3]--;
                nowx = 1;
            }
            else
            {
                cnt[2]--;
                ans.push_back(2);
                nowx = -1;
            }
        }
    }

    if (x != finalx && y != finaly && x != nowx && y != nowy)
    {
        while (cnt[1] && cnt[0])
        {
            ans.push_back(1);
            ans.push_back(0);
            cnt[1]--;
            cnt[0]--;
        }
        while (cnt[3] && cnt[2])
        {
            ans.push_back(2);
            ans.push_back(3);
            cnt[2]--;
            cnt[3]--;
        }
    }
    if (x == finalx || nowy == y)
    {
        while (cnt[0])
        {
            ans.push_back(0);
            cnt[0]--;
        }
        while (cnt[1])
        {
            ans.push_back(1);
            cnt[1]--;
        }
    }
    if (y == finaly || x == nowx)
    {
        while (cnt[2])
        {
            ans.push_back(2);
            cnt[2]--;
        }
        while (cnt[3])
        {
            ans.push_back(3);
            cnt[3]--;
        }
    }

    while (cnt[0])
    {
        ans.push_back(0);
        cnt[0]--;
    }
    while (cnt[1])
    {
        ans.push_back(1);
        cnt[1]--;
    }
    while (cnt[2])
    {
        ans.push_back(2);
        cnt[2]--;
    }
    while (cnt[3])
    {
        ans.push_back(3);
        cnt[3]--;
    }
    for (int i = 0; i < ans.size(); i++)
    {
        if (ans[i] == 0)
            cout << 'U';
        if (ans[i] == 1)
            cout << 'D';
        if (ans[i] == 2)
            cout << 'L';
        if (ans[i] == 3)
            cout << 'R';
    }
    cout << '\n';
    return;
}

signed main()
{
    //	freopen("in.txt", "r", stdin);
    //	freopen("out.out", "w", stdout);
    Blizzard; // false
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
/*
while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
*/

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:

LLRRUUD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3700kb

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:

RUDUDR
URU
Impossible
Impossible
Impossible
RRUUUDUUU
RRDRLDR
UD
Impossible
LDDLLLRR
LDRURLDD
Impossible
DUDDLLRDU
LL
Impossible
URDULUR
Impossible
Impossible
Impossible
LDLRLLDRRL
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LRURRLLRRU
LLUDL
Impossible
UUDDDLU
RURUDD
Impossi...

result:

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