QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506096#6422. Evil CoordinateEdisonBaAC ✓19ms3812kbC++147.4kb2024-08-05 15:13:372024-08-05 15:13:37

Judging History

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

  • [2024-08-05 15:13:37]
  • 评测
  • 测评结果:AC
  • 用时:19ms
  • 内存:3812kb
  • [2024-08-05 15:13:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re read()
#define INF 9223372036854775800
#define fr(i, x, y) for(int i = x, p = y; i <= p; ++i) 
#define rp(i, x, y) for(int i = x, p = y; i >= p; --i)
#define Timeok ((double)clock() / CLOCKS_PER_SEC < MAX_TIME)
const double MAX_TIME = 1.0 - 0.0032;

inline ll read()
{
   ll x = 0, f = 0;
   char ch = getchar();
   while (!isdigit(ch))
      f |= (ch == '-'), ch = getchar();
   while (isdigit(ch))
      x = (x << 1) + (x << 3) + (ch ^= 48), ch = getchar();
   return f ? -x : x;
}

void write(ll x)
{
   if (x < 0)
      putchar('-'), x = -x;
   if (x > 9)
      write(x / 10);
   putchar(x % 10 + 48);
}

inline void W(ll x, char ch)
{
    write(x);
    putchar(ch);
}

/*------------C-O-D-E------------*/

const int N = 1e5 + 4;
ll n, m, T, x, y;

int r, u, l, d;


int main()
{
    ll T = re;
    fr(t, 1, T)
    {
        // if(t == 5 && T == 5)
        // {
        //     puts("LDLRUUR");
        //     puts("UUU");
        //     puts("Impossible");
        //     puts("Impossible");
        //     puts("Impossible");
        //     return 0;
        // }
        // if(t != 34) continue;
        x = re, y = re;
        string s;
        cin>>s;
        // if(t == 35)
        // {
        //     cout<<x<<' '<<y<<endl;
        //     cout<<s<<endl;
        //     return 0;
        // }
        // else continue;
        
        if(x == 0 && y == 0)
        {
            puts("Impossible");
            continue;
        }
        int len = s.size();
        r = 0, u=0,l=0,d=0;
        fr(i,0,len - 1)
        {
            if(s[i] == 'R') ++r;
            if(s[i] == 'U') ++u;
            if(s[i] == 'L') ++l;
            if(s[i] == 'D') ++d;
        }
        ll nx = r - l, ny = u - d;
        // cout<<nx<<' '<<ny<<endl;
        if(nx == x && ny == y)
        {
            puts("Impossible");
            continue;
        }

        // Imposs ud
        if(l == 0 && r == 0)
        {
            if(ny > 0 && y > 0 && ny > y && x ==0)
            {
                puts("Impossible");
                continue;
            }
            if(ny < 0 && y < 0 && ny < y && x== 0)
            {
                puts("Impossible");
                continue;
            }
            if(y > 0)
            {
                fr(i,1,d) putchar('D');
                fr(i,1,u) putchar('U');
                puts("");
                continue;
            }
            if(y < 0)
            {
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                puts("");
                continue;
            }
            // continue;
        }

        // Imposs lr
        if(u == 0 && d == 0)
        {
            if(nx > 0 && x > 0 && nx > x && y == 0)
            {
                puts("Impossible");
                continue;
            }
            if(nx < 0 && x < 0 && nx < x && y == 0)
            {
                puts("Impossible");
                continue;
            }
            if(x > 0)
            {
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                puts("");
                continue;
            }
            if(x < 0)
            {
                fr(i,1,r) putchar('R');
                fr(i,1,l) putchar('L');
                puts("");
                continue;
            }
            // continue;
        }
        // puts("ok");
        // ud 1
        if(x == 0 && nx == 0)
        {
            if(ny > 0 && y > 0 && ny > y)
            {
                if(l) { --l; putchar('L'); }
                else { --r; putchar('R'); }
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                puts("");
                continue;
            }
            if(ny < 0 && y < 0 && ny < y)
            {
                if(l) { --l; putchar('L'); }
                else { --r; putchar('R'); }
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                puts("");
                continue;
            }
            if(y > 0)
            {
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                fr(i,1,d) putchar('D');
                fr(i,1,u) putchar('U');
                puts("");
                continue;
            }
            if(y < 0)
            {
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                puts("");
                continue;
            }
            // continue;
        }

        // lr 1
        if(y == 0 && ny == 0)
        {
            if(nx > 0 && x > 0 && nx > x)
            {
                if(u) { --u; putchar('U'); }
                else { --d; putchar('D'); }
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                puts("");
                continue;
            }
            if(nx < 0 && x < 0 && nx < x)
            {
                if(u) { --u; putchar('U'); }
                else { --d; putchar('D'); }
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                puts("");
                continue;
            }
            if(x > 0)
            {
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                fr(i,1,l) putchar('L');
                fr(i,1,r) putchar('R');
                puts("");
                continue;
            }
            if(x < 0)
            {
                fr(i,1,u) putchar('U');
                fr(i,1,d) putchar('D');
                fr(i,1,r) putchar('R');
                fr(i,1,l) putchar('L');
                puts("");
                continue;
            }
            // continue;
        }
        

        if(y == 0)
        {
            fr(i,1,u) putchar('U');
            fr(i,1,d) putchar('D');
            fr(i,1,l) putchar('L');
            fr(i,1,r) putchar('R');
            puts("");
            continue;
        }

        if(x == 0)
        {
            fr(i,1,l) putchar('L');
            fr(i,1,r) putchar('R');
            fr(i,1,u) putchar('U');
            fr(i,1,d) putchar('D');
            puts("");
            continue;
        }

        if(ny == y)
        {
            fr(i,1,l) putchar('L');
            fr(i,1,r) putchar('R');
            fr(i,1,u) putchar('U');
            fr(i,1,d) putchar('D');
            puts("");
            continue;
        }

        if(nx == x)
        {
            fr(i,1,u) putchar('U');
            fr(i,1,d) putchar('D');
            fr(i,1,l) putchar('L');
            fr(i,1,r) putchar('R');
            puts("");
            continue;
        }

        fr(i,1,u) putchar('U');
        fr(i,1,d) putchar('D');
        fr(i,1,l) putchar('L');
        fr(i,1,r) putchar('R');
        puts("");
        continue;
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 13ms
memory: 3596kb

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:

UUDDRR
UUR
Impossible
Impossible
Impossible
RRUUUUUUD
DDLRRRR
UD
Impossible
LLLLRRDD
LLRRUDDD
Impossible
UUDDDDLLR
LL
Impossible
UUUDLRR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
UUUDDDL
UUDDRR
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 19ms
memory: 3664kb

input:

11107
1 0
LLRLRURLR
1 0
LLRR
0 1
R
1 0
LLLRLRRR
1 0
RUL
0 1
UD
1 0
RLRLU
0 1
DDDUUUDU
1 0
RURRLLRLL
1 0
LRLR
1 0
ULR
0 1
R
0 1
DDUUUDR
0 1
UUDDUDDU
0 1
DDUUDU
1 0
RRLRLLRLRL
1 0
RLRRLL
1 0
LUR
1 0
U
1 0
LRRRLLLR
0 1
DRUUDDUDU
0 1
DUUDDUR
1 0
LRLRLR
0 1
UUDDDUDU
0 1
R
0 1
UDUDDU
0 1
DUUDUD
1 0
RRLRRR...

output:

ULLLLRRRR
LLRR
R
LLLLRRRR
ULR
DU
ULLRR
DDDDUUUU
ULLLLRRRR
LLRR
ULR
R
RUUUDDD
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
ULR
U
LLLLRRRR
RUUUUDDDD
RUUUDDD
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
ULLLLRRRR
DDUU
LLLRRR
ULR
ULR
U
ULR
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RUUUUDDDD
RUUUUDDDD
LLLRRR
...

result:

ok 11107 cases