QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642385#6422. Evil CoordinateSSAABBEERRWA 12ms3700kbC++205.5kb2024-10-15 13:43:532024-10-15 13:43:54

Judging History

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

  • [2024-10-15 13:43:54]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3700kb
  • [2024-10-15 13:43:53]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);  
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
using namespace std;
const int N = 1e6 + 10;
int n, m;
int tx, ty;
string s;
int c[4];
void solve()
{   
    cin >> tx >> ty >> s;
    n = s.size();
    s = " " + s;
    rep(i, 0, 3) c[i] = 0;
    rep(i, 1, n) 
    {
        if(s[i] == 'L') c[0] ++ ;
        else if(s[i] == 'R') c[1] ++ ;
        else if(s[i] == 'U') c[2] ++ ;
        else c[3] ++ ;
    }
    int xx = 0, yy = 0;
    xx -= c[0];
    xx += c[1];
    yy += c[2];
    yy -= c[3];
    if(xx == tx && yy == ty)
    {
        cout << "Impossible";
    }
    else if(!tx && !ty)
    {
        cout << "Impossible";
    }
    else if(yy != ty)
    {
        if(tx != 0)
        {
            while(c[0] -- ) cout << "L";
            while(c[1] -- ) cout << "R";
            while(c[2] -- ) cout << "U";
            while(c[3] -- ) cout << "D"; 
        }
        else
        {
            if(xx != 0) 
            {
                while(c[0] -- ) cout << "L";
                while(c[1] -- ) cout << "R";
                while(c[2] -- ) cout << "U";
                while(c[3] -- ) cout << "D"; 
            }
            else
            {
                if(c[0])
                {
                    while(c[0] -- ) cout << "L";
                    while(c[2] -- ) cout << "U";
                    while(c[3] -- ) cout << "D"; 
                    while(c[1] -- ) cout << "R";
                }
                else if(c[1])
                {
                    while(c[1] -- ) cout << "R";
                    while(c[0] -- ) cout << "L";
                    while(c[2] -- ) cout << "U";
                    while(c[3] -- ) cout << "D";                    
                }
                else
                {
                    if(min(0ll, yy) <= ty && max(0ll, yy) >= ty)
                    {
                        cout << "Impossible";
                    }
                    else
                    {
                        if(yy != 0)
                        {
                            if(yy > 0)
                            {
                                int f = 0;
                                while(c[2] || c[3])
                                {
                                    if(!f && c[2]) cout << "U", c[2] -- ;
                                    else if(f && c[3]) cout << "D", c[3] -- ;
                                    else if(c[2]) cout << "U", c[2] -- ;
                                    else cout << "D", c[3] -- ;
                                    f ^= 1;
                                }
                            }
                            else
                            {
                                int f = 0;
                                while(c[2] || c[3])
                                {
                                    if(f && c[2]) cout << "U", c[2] -- ;
                                    else if(!f && c[3]) cout << "D", c[3] -- ;
                                    else if(c[2]) cout << "U", c[2] -- ;
                                    else cout << "D", c[3] -- ;
                                    f ^= 1;
                                }
                            }
                        }
                        else
                        {
                            if(ty > 0) while(c[2] -- ) cout << "DU";
                            else while(c[3] -- ) cout << "UD";
                        }
                    }
                }
            }
        }
    }
    else if(yy == ty)
    {
        if(ty != 0)
        {
            while(c[0] -- ) cout << "L";
            while(c[1] -- ) cout << "R";
            while(c[2] -- ) cout << "U";
            while(c[3] -- ) cout << "D"; 
        }
        else
        {
            if(min(0ll, xx) <= tx && max(0ll, xx) >= tx)
            {
                cout << "Impossible";
            }
            else
            {
                if(xx != 0)
                {
                    if(xx < 0)
                    {
                        int f = 0;
                        while(c[0] || c[1])
                        {
                            if(!f && c[0]) cout << "L", c[0] -- ;
                            else if(f && c[1]) cout << "R", c[1] -- ;
                            else if(c[0]) cout << "L", c[0] -- ;
                            else cout << "R", c[1] -- ;
                            f ^= 1;
                        }
                    }
                    else
                    {
                        int f = 0;
                        while(c[0] || c[1])
                        {
                            if(f && c[0]) cout << "L", c[0] -- ;
                            else if(!f && c[1]) cout << "R", c[1] -- ;
                            else if(c[0]) cout << "L", c[0] -- ;
                            else cout << "R", c[1] -- ;
                            f ^= 1;
                        }
                    }
                }
                else
                {
                    if(tx < 0) while(c[0] -- ) cout << "RL";
                    else while(c[0] -- ) cout << "LR";
                }
            }
        }
    }
    cout << endl;
}
signed main()
{
    IOS;
	int _;
	_ = 1;
	cin >> _;
	while(_--)
	{
	    solve();
	}
	return 0;
}

详细

Test #1:

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

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: -100
Wrong Answer
time: 12ms
memory: 3700kb

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:

RR
RUU
Impossible
Impossible
Impossible
RRUUUUUUD
LRRRRDD

Impossible
LLLLRRDD
LLRRUDDD
Impossible
LLRUUDDDD
LL
Impossible
LRRUUUD
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
LLLUD
Impossible
L
RRUUDD
Impossible
RLR
RRUU...

result:

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