QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682358#6422. Evil CoordinateBlizzardCompile Error//C++1411.2kb2024-10-27 15:08:152024-10-27 15:08:16

Judging History

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

  • [2024-10-27 15:08:16]
  • 评测
  • [2024-10-27 15:08:15]
  • 提交

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;
   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

answer.code: In function ‘void solve()’:
answer.code:198:12: error: redeclaration of ‘std::string ans’
  198 |     string ans;
      |            ^~~
answer.code:58:12: note: ‘std::string ans’ previously declared here
   58 |     string ans;
      |            ^~~