QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506233#6422. Evil CoordinatexixuWA 19ms3836kbC++174.8kb2024-08-05 16:09:492024-08-05 16:09:49

Judging History

This is the latest submission verdict.

  • [2024-08-05 16:09:49]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 3836kb
  • [2024-08-05 16:09:49]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
// #define int short
#define int long long

typedef long long ll;


// const int M = 1e4 + 10 , inf = 0x3f3f3f3f , N = 1e6 + 10;

int f = 0;




void solve()
{
    int x , y;
    cin >> x >> y;
    
    string s;
    cin >> s;
    map<char , int> mp;
    map<char , int> mmp;
    for(int i = 0; s[i]; i ++)
    {
        if(s[i] == 'U')
        {
            mp['y'] ++;
            mmp['U'] ++;
        }
        else if(s[i] == 'D')
        {
            mp['y'] --;
            mmp['D'] ++;
        }
        else if(s[i] == 'L')
        {
            mp['x'] --;
            mmp['L'] ++;
        }
        else
        {
            mp['x'] ++;
            mmp['R'] ++;
        }
    }

    // cout << mp['y'] << ' ' << y << '\n';
    if((mp['x'] == x && mp['y'] == y) || (!x && !y) || (!mmp['D'] && !mmp['U'] && !y && ((mp['x'] >= x && x >= 0) || (mp['x'] <= x && x <= 0))) || (!mmp['L'] && !mmp['R'] && !x && ((mp['y'] >= y && y > 0) || (mp['y'] <= y && y < 0))))
    {
        cout << "Impossible\n";
        return ;
    }
    // || (!mp['x'] && !x && ((y > 0 && mp['y'] >= y) || (y <= 0 && mp['y'] <= y))) || (!mp['y'] && !y && ((x > 0 && mp['x'] >= x) || (x <= 0 && mp['x'] <= x))) || 

    // if((mp['x'] == x && mp['y'] == y) || (!x && !y) || (!mp['x'] && !x && ((y > 0 && mp['y'] >= y) || (y <= 0 && mp['y'] <= y))) || (!mp['y'] && !y && ((x > 0 && mp['x'] >= x) || (x <= 0 && mp['x'] <= x))))
    // {
    //     cout << "Impossible\n";
    //     return ;
    // }

    
    if(y >= 0)
    {
        for(int i = 1; i <= mmp['D']; i ++)
        {
            cout << 'D';
        }
    }
    else
    {
        for(int i = 1; i <= mmp['U']; i ++)
        {
            cout << 'U';
        }
    }

    if(x >= 0)
    {
        for(int i = 1; i <= mmp['L']; i ++)
        {
            cout << 'L';
        }
        if(y >= 0)//UR
        {
            if(mp['y'] != y)
            {
                for(int i = 1; i <= mmp['U']; i ++)
                {
                    cout << 'U';
                }
                for(int i = 1; i <= mmp['R']; i ++)
                {
                    cout << 'R';
                }

            }
            else
            {
                for(int i = 1; i <= mmp['R']; i ++)
                {
                    cout << 'R';
                }
                for(int i = 1; i <= mmp['U']; i ++)
                {
                    cout << 'U';
                }
            }
        }
        else//DR
        {
            if(mp['y'] != y)
            {
                for(int i = 1; i <= mmp['D']; i ++)
                {
                    cout << 'D';
                }
                for(int i = 1; i <= mmp['R']; i ++)
                {
                    cout << 'R';
                }
            }
            else
            {
                for(int i = 1; i <= mmp['R']; i ++)
                {
                    cout << 'R';
                }
                for(int i = 1; i <= mmp['D']; i ++)
                {
                    cout << 'D';
                }
            }
        }
    }
    else
    {
        for(int i = 1; i <= mmp['R']; i ++)
        {
            cout << 'R';
        }
        if(y >= 0)//UL
        {
            if(mp['y'] != y)
            {
                for(int i = 1; i <= mmp['U']; i ++)
                {
                    cout << 'U';
                }
                for(int i = 1; i <= mmp['L']; i ++)
                {
                    cout << 'L';
                }
            }
            else
            {
                for(int i = 1; i <= mmp['L']; i ++)
                {
                    cout << 'L';
                }
                for(int i = 1; i <= mmp['U']; i ++)
                {
                    cout << 'U';
                }
            }
        }
        else//DL
        {
            if(mp['y'] != y)
            {
                for(int i = 1; i <= mmp['D']; i ++)
                {
                    cout << 'D';
                }
                for(int i = 1; i <= mmp['L']; i ++)
                {
                    cout << 'L';
                }
            }
            else
            {
                for(int i = 1; i <= mmp['L']; i ++)
                {
                    cout << 'L';
                }
                for(int i = 1; i <= mmp['D']; i ++)
                {
                    cout << 'D';
                }
            }
        }
    }
    cout << '\n';
    




}



signed main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);

    int _ = 1;
    cin >> _;
    while(_ --)
    {
        solve();
    }


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

DLLRRUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 3824kb

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:

DDRRUU
UUR
Impossible
Impossible
Impossible
DRRUUUUUU
DDRRRRL
DU
Impossible
LLLLRRDD
ULLRRDDD
Impossible
DDDDRUULL
LL
Impossible
DLUUURR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
DDDLUUU
UUDDRR
Impossi...

result:

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