QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506210#6422. Evil CoordinateUmokWA 0ms3528kbC++204.8kb2024-08-05 15:59:102024-08-05 15:59:11

Judging History

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

  • [2024-08-05 15:59:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2024-08-05 15:59:10]
  • 提交

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;
    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;
        }
    }
    if (a == 0)
    {

        for (int i = 1; i <= min(u, d); i++)
            cout << "D";
        for (int i = min(u, d) + 1; i <= d; i++)
            cout << "D";
        for (int i = min(u, d) + 1; i <= u; i++)
            cout << "U";
        if (a > 0)
        {
            for (int i = 1; i <= l; i++)
                cout << "L";
            for (int i = 1; i <= r; i++)
                cout << "R";
        }
        else
        {
            for (int i = 1; i <= r; i++)
                cout << "R";
            for (int i = 1; i <= l; i++)
                cout << "L";
        }
        return;
    }
    else if (b == 0)
    {
        if (a > 0)
        {
            for (int i = 1; i <= l; i++)
                cout << "L";
            for (int i = 1; i <= r; i++)
                cout << "R";
        }
        else
        {
            for (int i = 1; i <= r; i++)
                cout << "R";
            for (int i = 1; i <= l; i++)
                cout << "L";
        }
        for (int i = 1; i <= min(u, d); i++)
            cout << "UD";
        for (int i = min(u, d) + 1; i <= d; i++)
            cout << "D";
        for (int i = min(u, d) + 1; i <= u; i++)
            cout << "U";
        return;
    }

    if (a == x)
    {
        if (b > 0)
        {
            for (int i = 1; i <= min(d, u); i++)
                cout << "DU";
            for (int i = min(d, u) + 1; i <= d; i++)
                cout << "D";
            for (int i = min(d, u) + 1; i <= u; i++)
                cout << "U";
        }
        else
        {
            for (int i = 1; i <= min(d, u); i++)
                cout << "UD";
            for (int i = min(d, u) + 1; i <= u; i++)
                cout << "U";
            for (int i = min(d, u) + 1; i <= d; i++)
                cout << "D";
        }
        if (a > 0)
        {
            for (int i = 1; i <= min(l, r); i++)
                cout << "LR";
            for (int i = min(l, r) + 1; i <= l; i++)
                cout << "L";
            for (int i = min(l, r) + 1; i <= r; i++)
                cout << "R";
        }
        else
        {
            for (int i = 1; i <= min(l, r); i++)
                cout << "RL";
            for (int i = min(l, r) + 1; i <= r; i++)
                cout << "R";
            for (int i = min(l, r) + 1; i <= l; i++)
                cout << "L";
        }
    }
    else
    {
        if (a > 0)
        {
            for (int i = 1; i <= min(l, r); i++)
                cout << "LR";
            for (int i = min(l, r) + 1; i <= l; i++)
                cout << "L";
            for (int i = min(l, r) + 1; i <= r; i++)
                cout << "R";
        }
        else
        {
            for (int i = 1; i <= min(l, r); i++)
                cout << "RL";
            for (int i = min(l, r) + 1; i <= r; i++)
                cout << "R";
            for (int i = min(l, r) + 1; i <= l; i++)
                cout << "L";
        }
        if (b > 0)
        {
            for (int i = 1; i <= min(d, u); i++)
                cout << "DU";
            for (int i = min(d, u) + 1; i <= d; i++)
                cout << "D";
            for (int i = min(d, u) + 1; i <= u; i++)
                cout << "U";
        }
        else
        {
            for (int i = 1; i <= min(d, u); i++)
                cout << "UD";
            for (int i = min(d, u) + 1; i <= u; i++)
                cout << "U";
            for (int i = min(d, u) + 1; i <= d; i++)
                cout << "D";
        }
    }
    cout << endl;
}

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

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3528kb

input:

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

output:

LRLRDUU
UUUImpossible
Impossible
Impossible

result:

wrong answer Line "UUUImpossible" doesn't correspond to pattern "[UDLR]{1,100000}|Impossible"