QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#149261#6422. Evil CoordinateylfWA 17ms3608kbC++146.8kb2023-08-24 11:27:302023-08-24 11:27:34

Judging History

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

  • [2023-08-24 11:27:34]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3608kb
  • [2023-08-24 11:27:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=3e5+10;
ll t,x,y,n,u,d,l,r;
char s[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    
    cin>>t;
    while(t--)
    {
        u=d=l=r=0;
        cin>>x>>y;
        cin>>(s+1);
        n=strlen(s+1);
        for(ll a=1;a<=n;a++)
        {
            if(s[a]=='U') u++;
            else if(s[a]=='D') d++;
            else if(s[a]=='L') l++;
            else r++;
        }
        if(u-d==y&&r-l==x) cout<<"Impossible";
        else
        {
            if(y==0)
            {
                if(x==0) cout<<"Impossible";
                else if(x<0)
                {
                    if(u==d)
                    {
                        if(u==0)
                        {
                            if(r-l>x) 
                            {
                                for(ll a=1;a<=r;a++) cout<<"R";
                                for(ll a=1;a<=l;a++) cout<<"L";
                            }
                            else 
                            {
                                cout<<"Impossible";
                            }
                        }
                        else
                        {
                            for(ll a=1;a<=u;a++) cout<<"U";
                            for(ll a=1;a<=r;a++) cout<<"R";
                            for(ll a=1;a<=l;a++) cout<<"L";
                            for(ll a=1;a<=d;a++) cout<<"D";
                        }
                    }
                    else
                    {
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                    }
                }
                else//x>0
                {
                    if(u==d)
                    {
                        if(u==0)
                        {
                            if(r-l<x) 
                            {
                                for(ll a=1;a<=l;a++) cout<<"L";
                                for(ll a=1;a<=r;a++) cout<<"R";
                            }
                            else 
                            {
                                cout<<"Impossible";
                            }
                        }
                        else
                        {
                            for(ll a=1;a<=u;a++) cout<<"U";
                            for(ll a=1;a<=r;a++) cout<<"R";
                            for(ll a=1;a<=l;a++) cout<<"L";
                            for(ll a=1;a<=d;a++) cout<<"D";
                        }
                    }
                    else
                    {
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                    }
                }
            }

            else if(y>0)
            {
                if(x==0)
                {
                    if(l==r)
                    {
                        if(l==0)
                        {
                            if(u-d>y) cout<<"Impossible";
                            else 
                            {
                                for(ll a=1;a<=d;a++) cout<<"D";
                                for(ll a=1;a<=u;a++) cout<<"U";
                            }
                        }
                        else
                        {
                            for(ll a=1;a<=r;a++) cout<<"R";
                            for(ll a=1;a<=u;a++) cout<<"U";
                            for(ll a=1;a<=d;a++) cout<<"D";
                            for(ll a=1;a<=l;a++) cout<<"L";
                        }
                    }
                    else
                    {
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                    }
                
                }
                else
                {
                    if(r-l==x)
                    {
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                    }
                    else
                    {
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                    }
                }
            }
            else
            {
                if(x==0)
                {
                    if(l==r)
                    {
                        if(l==0)
                        {
                            if(u-d<y) cout<<"Impossible";
                            else 
                            {
                                for(ll a=1;a<=d;a++) cout<<"U";
                                for(ll a=1;a<=u;a++) cout<<"D";
                            }
                        }
                        else
                        {
                            for(ll a=1;a<=r;a++) cout<<"R";
                            for(ll a=1;a<=u;a++) cout<<"U";
                            for(ll a=1;a<=d;a++) cout<<"D";
                            for(ll a=1;a<=l;a++) cout<<"L";
                        }
                    }
                    else
                    {
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                    }
                
                }
                else
                {
                    if(r-l==x)
                    {
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                    }
                    else
                    {
                        for(ll a=1;a<=r;a++) cout<<"R";
                        for(ll a=1;a<=l;a++) cout<<"L";
                        for(ll a=1;a<=u;a++) cout<<"U";
                        for(ll a=1;a<=d;a++) cout<<"D";
                    }
                }
            }
        }
        cout<<"\n";
    }
}

//https://cftracker.netlify.app/contests

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

input:

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

output:

RRLLUUD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 3492kb

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
RRUUUUUUD
RRRRLDD
UD
Impossible
RRLLLLDD
RRLLUDDD
Impossible
UUDDDDRLL
LL
Impossible
UUUDRRL
Impossible
Impossible
Impossible
RRRLLLLLDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
RRRRRLLLUU
LLLUD
Impossible
UUULDDD
UUDDRR
Impossi...

result:

wrong answer case 113, participant's output is not a permutation of the input