QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506209#6422. Evil CoordinateDreamy_BlazeWA 25ms4052kbC++147.2kb2024-08-05 15:58:552024-08-05 15:58:55

Judging History

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

  • [2024-08-05 15:58:55]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:4052kb
  • [2024-08-05 15:58:55]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define fr(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define br(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define PI acos(-1)
using namespace std;

const int maxn = 14e2 + 3;

void solve()
{
    int x, y;
    cin >> x >> y;
    string s;
    cin >> s;
    map<char, int> mp;
    for (int i = 0; i < s.size(); i++)
    {
        mp[s[i]]++;
    }
    if (x == 0 && y == 0)
    {
        cout << "Impossible" << endl;
        return;
    }
    int xx = 0, yy = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'U')
        {
            yy++;
        }
        else if (s[i] == 'D')
        {
            yy--;
        }
        else if (s[i] == 'L')
            xx--;
        else if (s[i] == 'R')
            xx++;
    }
    // cout << x << " " << y << endl;
    if (xx == x && yy == y)
    {
        cout << "Impossible" << endl;
        return;
    }
    // cout<<xx<<" "<<yy<<" "<<x<<" "<<y<<endl;
    if (mp['L'] == 0 && mp['R'] == 0 && xx == 0 && x == 0 && ((y > 0 && yy > 0 && yy >= y) || (y < 0 && yy < 0 && yy <= y)))
    {
        cout << "Impossible" << endl;
        return;
    }
    if (mp['D'] == 0 && mp['U'] == 0 && yy == 0 && y == 0 && ((x > 0 && xx > 0 && xx >= x) || (x < 0 && xx < 0 && xx <= x)))
    {
        cout << "Impossible" << endl;
        return;
    }
    if (x > 0)
    {
        if (mp['L'])
        {
            fr(i, 1, mp['L'])
            {
                cout << "L";
            }
        }
        if (y > 0)
        {
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
            if (xx == x)
            {
                if (mp['R'])
                {
                    mp['R']--;
                    fr(i, 1, mp['R'])
                    {
                        cout << "R";
                    }
                    mp['R']++;
                }
                // mp['R']++;
            }
            else
            {
                if (mp['R'])
                {
                    fr(i, 1, mp['R'])
                    {
                        cout << "R";
                    }
                }
            }
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
            if (xx == x && mp['R'] != 0)
                cout << "R";
        }
        else
        {
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
            if (xx == x)
            {
                if (mp['R'])
                {
                    mp['R']--;
                    fr(i, 1, mp['R'])
                    {
                        cout << "R";
                    }
                    mp['R']++;
                }
            }
            else
            {
                if (mp['R'])
                {
                    fr(i, 1, mp['R'])
                    {
                        cout << "R";
                    }
                }
            }
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
            if (xx == x && mp['R'] != 0)
                cout << "R";
        }
        cout << endl;
        return;
    }
    if (x < 0)
    {
        if (mp['R'])
        {
            fr(i, 1, mp['R'])
            {
                cout << "R";
            }
        }
        if (y > 0)
        {
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
            if (xx == x)
            {
                if (mp['L'])
                {
                    mp['L']--;
                    fr(i, 1, mp['L'])
                    {
                        cout << "L";
                    }
                    mp['L']++;
                }
            }
            else
            {
                if (mp['L'])
                {
                    fr(i, 1, mp['L'])
                    {
                        cout << "L";
                    }
                }
            }
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
            if (xx == x && mp['L'] != 0)
                cout << "L";
        }
        else
        {
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
            if (xx == x)
            {
                if (mp['L'])
                {
                    mp['L']--;
                    fr(i, 1, mp['L'])
                    {
                        cout << "L";
                    }
                    mp['L']++;
                }
            }
            else
            {
                if (mp['L'])
                {
                    fr(i, 1, mp['L'])
                    {
                        cout << "L";
                    }
                }
            }
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
            if (xx == x && mp['L'])
                cout << "L";
        }
        cout << endl;
        return;
    }
    if (x == 0)
    {
        int f = 0;
        if (mp['L'])
        {
            fr(i, 1, mp['L'])
            {
                cout << "L";
            }
            f = 1;
        }
        if (!f)
        {
            if (mp['R'])
            {
                fr(i, 1, mp['R'])
                {
                    cout << "R";
                }
            }
        }
        if (y > 0)
        {
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
        }
        else
        {
            if (mp['U'])
            {
                fr(i, 1, mp['U'])
                {
                    cout << "U";
                }
            }
            if (mp['D'])
            {
                fr(i, 1, mp['D'])
                {
                    cout << "D";
                }
            }
        }
        if (f)
        {
            if (mp['R'])
            {
                fr(i, 1, mp['R'])
                {
                    cout << "R";
                }
            }
        }
        cout << endl;
        return;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

詳細信息

Test #1:

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

input:

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

output:

LLDRRUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 4052kb

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
RRDUUUUUU
RRRRDDL
UD
Impossible
LLLLRRDD
LLURRDDD
Impossible
RUULDDDDL
LL
Impossible
LDRUUUR
Impossible
Impossible
Impossible
LLLLLDDRRR
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLUURRRRR
ULLLD
Impossible
UUULDDD
UURDDR
Impossi...

result:

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