QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506129#6422. Evil CoordinatepagohiaWA 15ms3900kbC++144.0kb2024-08-05 15:31:422024-08-05 15:31:43

Judging History

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

  • [2024-08-05 15:31:43]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3900kb
  • [2024-08-05 15:31:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 100005



void solve()
{
    int x,y;
    string str1="";
    char str[N];
    cin>>x>>y;
    cin>>str;
    int u=0;
    int d=0;
    int l=0;
    int r=0;
    for(int i=0;i<strlen(str);i++)
    {
        if(str[i]=='U')
            u++;
        else if(str[i]=='D')
            d++;
        else if(str[i]=='L')
            l++;
        else if(str[i]=='R')
            r++;
    }

    if(x==0&&y==0)
        cout<<"Impossible"<<endl;
    else if((l||r)&&!u&&!d)
    {
        int xx=1;
        if(y==0&&x>=0&&r-l>=x)
        {
            cout<<"Impossible"<<endl;
            xx=0;
        }
        else if(y==0&&x<0&&r-l<=x)
        {
            cout<<"Impossible"<<endl;
            xx=0;
        }
        if(xx==1)
        {
            if(x>=0)
        {
            for(int i=0;i<l;i++)
            str1+='L';
            for(int i=0;i<r;i++)
            str1+='R';
            cout<<str1<<endl;
        }
        else if(x<0)
        {
            for(int i=0;i<r;i++)
            str1+='R';
            for(int i=0;i<l;i++)
            str1+='L';
            cout<<str1<<endl;
        }
        }
    }
    else if((u||d)&&!l&&!r)
    {
        int xx=1;
        if(x==0&&y>=0&&u-d>=y)
        {
            cout<<"Impossible"<<endl;
            xx=0;
        }
        else if(x==0&&y<0&&u-d<=y)
        {
            cout<<"Impossible"<<endl;
            xx=0;
        }
        if(xx==1)
        {
            if(y>=0)
        {
            for(int i=0;i<d;i++)
            str1+='D';
            for(int i=0;i<u;i++)
            str1+='U';
            cout<<str1<<endl;
        }
        else if(y<0)
        {
            for(int i=0;i<u;i++)
            str1+='U';
            for(int i=0;i<d;i++)
            str1+='D';
            cout<<str1<<endl;
        }
        }
    }
    else if(r-l==x&&u-d==y)
        cout<<"Impossible"<<endl;
    else
    {
        int dx=r-l;
        int dy=u-d;
        if(dx==x&&dy!=y)
        {
            if(x!=r)
            {
                for(int i=0;i<r;i++)
                    str1+='R';
                for(int i=0;i<u;i++)
                    str1+='U';
                for(int i=0;i<d;i++)
                    str1+='D';
                for(int i=0;i<l;i++)
                    str1+='L';
                cout<<str1<<endl;
            }
            else 
            {
                for(int i=0;i<l;i++)
                    str1+='L';
                for(int i=0;i<u;i++)
                    str1+='U';
                for(int i=0;i<d;i++)
                    str1+='D';
                for(int i=0;i<r;i++)
                    str1+='R';
                cout<<str1<<endl;
            }
        }
        else if(dy==y&&dx!=x)
        {
            if(y!=u)
            {
                for(int i=0;i<u;i++)
                    str1+='U';
                for(int i=0;i<r;i++)
                    str1+='R';
                for(int i=0;i<l;i++)
                    str1+='L';
                for(int i=0;i<d;i++)
                    str1+='D';
                cout<<str1<<endl;
            }
            else 
            {
                for(int i=0;i<d;i++)
                    str1+='D';
                for(int i=0;i<r;i++)
                    str1+='R';
                for(int i=0;i<l;i++)
                    str1+='L';
                for(int i=0;i<u;i++)
                    str1+='U';
                cout<<str1<<endl;
            }
        }
        else
        {
            for(int i=0;i<r;i++)
                    str1+='R';
            for(int i=0;i<l;i++)
                    str1+='L';
            for(int i=0;i<u;i++)
                    str1+='U';
            for(int i=0;i<d;i++)
                    str1+='D';
            cout<<str1<<endl;
        }
    }
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

UURRLLD
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3816kb

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
RUU
Impossible
Impossible
Impossible
UUUUUURRD
RRRRLDD
DU
Impossible
RRLLLLDD
URRLLDDD
Impossible
RUUDDDDLL
LL
Impossible
RRUUUDL
Impossible
Impossible
Impossible
RRRLLLLLDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
RRRRRLLLUU
LLLUD
Impossible
UUULDDD
UUDDRR
Impossi...

result:

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