QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506029#6422. Evil CoordinateTimeless123WA 11ms3688kbC++174.4kb2024-08-05 14:47:052024-08-05 14:47:07

Judging History

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

  • [2024-08-05 14:47:07]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3688kb
  • [2024-08-05 14:47:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18
int x,y;
string s;

void solve()
{
    cin>>x>>y;
    cin>>s;
    if(!x && !y)
    {
        cout<<"Impossible"<<'\n';
        return ;
    }
    int L=0,R=0,U=0,D=0;
    for(int i=0;i<s.size();++i) 
    {
        if(s[i]=='U') U++;
        else if(s[i]=='D') D++;
        else if(s[i]=='R') R++;
        else L++;
    }

    if(U - D == y && R - L == x) 
    {
        cout<<"Impossible"<<'\n';
        return ;
    }

    if(x!=0 && y!=0) 
    {
        if(x>0 && y>0)
        {
            for(int i=1;i<=L;++i) cout<<'L';
            for(int i=1;i<=D;++i) cout<<'D';
            for(int i=1;i<=U;++i) cout<<'U';
            for(int i=1;i<=R;++i) cout<<'R';
        }
        else if(x<0 && y>0)
        {
            for(int i=1;i<=R;++i) cout<<'R';
            for(int i=1;i<=L;++i) cout<<'L';
            for(int i=1;i<=D;++i) cout<<'D';
            for(int i=1;i<=U;++i) cout<<'U';
        }
        else if(x<0 && y<0)
        {
            for(int i=1;i<=U;++i) cout<<'U';
            for(int i=1;i<=R;++i) cout<<'R';
            for(int i=1;i<=L;++i) cout<<'L';
            for(int i=1;i<=D;++i) cout<<'D';
            
        }
        else if(x>0 && y<0)
        {
            for(int i=1;i<=U;++i) cout<<'U';
            for(int i=1;i<=L;++i) cout<<'L';
            for(int i=1;i<=D;++i) cout<<'D';
            for(int i=1;i<=R;++i) cout<<'R';
        }
    }
    else if(x==0 && y!=0)
    {
        if(!(L+R))
        {
            if(y<0) 
            {
                if(D > U && abs(D-U)>=abs(y))
                {
                    cout<<"Impossible"<<'\n';
                     return ;
                }
                else
                {
                    for(int i=1;i<=U;++i) cout<<'U';
                    for(int i=1;i<=D;++i) cout<<'D';
                }

            }
            else
            {
                if(U > D && abs(D-U)>=abs(y))
                {
                    cout<<"Impossible"<<'\n';
                     return ;
                }
                else
                {
                    for(int i=1;i<=D;++i) cout<<'D';
                    for(int i=1;i<=U;++i) cout<<'U';
                }
            }
        }
        else 
        {
            if(y>0)
            {
                for(int i=1;i<=L;++i) cout<<'L';
                for(int i=1;i<=U;++i) cout<<'U';
                for(int i=1;i<=R;++i) cout<<'R';
                for(int i=1;i<=D;++i) cout<<'D';
                
            }       
            else 
            {
                for(int i=1;i<=L;++i) cout<<'L';
                for(int i=1;i<=U;++i) cout<<'U';
                for(int i=1;i<=R;++i) cout<<'R';
                for(int i=1;i<=D;++i) cout<<'D';
            }
        }
    }
    else 
    {
        if(!(U+D))
        {
            if(x<0) 
            {
                if(L > R && abs(L-R)>=abs(x))
                {
                    cout<<"Impossible"<<'\n';
                     return ;
                }
                else
                {
                    for(int i=1;i<=R;++i) cout<<'R';
                    for(int i=1;i<=L;++i) cout<<'L';
                }

            }
            else
            {
                if(R > L && abs(R-L)>=abs(x))
                {
                    cout<<"Impossible"<<'\n';
                     return ;
                }
                else
                {
                    for(int i=1;i<=L;++i) cout<<'L';
                    for(int i=1;i<=R;++i) cout<<'R';
                }
            }
        }
        else 
        {
            if(x>0)
            {
                for(int i=1;i<=L;++i) cout<<'L';
                for(int i=1;i<=D;++i) cout<<'D';
                for(int i=1;i<=U;++i) cout<<'U';
                for(int i=1;i<=R;++i) cout<<'R';
                
            }       
            else 
            {
                for(int i=1;i<=U;++i) cout<<'U';
                for(int i=1;i<=R;++i) cout<<'R';
                for(int i=1;i<=L;++i) cout<<'L';
                for(int i=1;i<=D;++i) cout<<'D';
            }
        }
    }
    cout<<'\n';
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;  cin>>_;
    while (_--) solve();
    return 0;
} 

詳細信息

Test #1:

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

input:

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

output:

LLDUURR
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3688kb

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:

DDUURR
UUR
Impossible
Impossible
Impossible
RRDUUUUUU
RRRRLDD
DU
Impossible
LLLLDDRR
ULLDDDRR
Impossible
UURLLDDDD
LL
Impossible
LDUUURR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLUURRRRR
ULLLD
Impossible
UUULDDD
UUDDRR
Impossi...

result:

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