QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685167#6422. Evil Coordinateadivse#WA 12ms4032kbC++204.8kb2024-10-28 18:00:462024-10-28 18:00:47

Judging History

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

  • [2024-10-28 18:00:47]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4032kb
  • [2024-10-28 18:00:46]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename T>
void cc(vector<T> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void cc(int a) { cout << a << endl; }
void cc(int a, int b) { cout << a << ' ' << b << endl; }
void cc(int a, int b, int c) { cout << a << ' ' << b << ' ' << c << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
void cmax(int& a, const int b) { if (b > a) a = b; }
void cmin(int& a, const int b) { if (b < a) a = b; }
using PII = pair<int, int>;
using i128 = __int128;

//--------------------------------------------------------------------------------
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int zx, zy;
int tx, ty;
int A[4];//0 shang 1 xia 2 zuo 3 you
//--------------------------------------------------------------------------------
void shang() {
    rep(i, 1, A[0]) cout << 'U';
    rep(i, 1, A[1]) cout << 'D';
}
void zuo() {
    rep(i, 1, A[2]) cout << 'L';
    rep(i, 1, A[3]) cout << 'R';
}
signed main() {
    kuaidu();
    T = 1;
    cin >> T;
    while (T--) {
        cin >> zx >> zy;
        string s; cin >> s;
        rep(i, 0, 3) A[i] = 0;
        tx = 0, ty = 0;
        rep(i, 0, s.size() - 1) {
            if (s[i] == 'U') A[0]++, ty += 1;
            if (s[i] == 'L') A[2]++, tx -= 1;
            if (s[i] == 'D') A[1]++, ty -= 1;
            if (s[i] == 'R') A[3]++, tx += 1;
        }

        if (zx == 0 and zy == 0) {
            cout << "Impossible" << endl;
            continue;
        }

        if (zx == tx and zy == ty) {
            cout << "Impossible" << endl;
            continue;
        }

        if (zx and zy) {

            if (ty == zy) {
                zuo(), shang();
                cout << endl;

                continue;
            }

            if (tx == zx) {
                shang(), zuo();
                cout << endl;

                continue;
            }
            shang(); zuo();
            cout << endl;

            continue;
        }

        if (tx and ty) {
            if (zx == 0) {
                zuo(), shang();
                cout << endl;

                continue;
            }
            if (zy == 0) {
                shang(); zuo();
                cout << endl;

                continue;
            }
            continue;
        }

        if (zx and ty or zy and tx) {
            if (zx and ty) {
                shang(), zuo();
                cout << endl;

                continue;
            }
            if (zy and tx) {
                zuo(), shang();
                cout << endl;

                continue;
            }
        }

        if (zx) {

            if (zx * tx > 0 and abs(zx) > abs(tx) || zx * tx < 0) {
                if (zx < 0) {
                    shang();
                    rep(i, 1, A[3]) cout << 'R';
                    rep(i, 1, A[2]) cout << 'L';
                }
                if (zx > 0) {
                    shang();
                    rep(i, 1, A[2]) cout << 'L';
                    rep(i, 1, A[3]) cout << 'R';
                }
                cout << endl;

                continue;
            }

            if (!A[0]) {
                cout << "Impossible" << endl;
                continue;
            }
            //0 shang 1 xia 2 zuo 3 you
            cout << 'U';
            zuo();
            rep(i, 2, A[0]) cout << 'U';
            rep(i, 1, A[1]) cout << 'D';
            cout << endl;

            continue;
        }

        if (zy) {

            if (zy * ty > 0 and abs(zy) > abs(ty) or zy * ty < 0) {
                if (zy < 0) {
                    zuo();
                    rep(i, 1, A[0]) cout << 'U';
                    rep(i, 1, A[1]) cout << 'D';
                }
                if (zy > 0) {
                    zuo();
                    rep(i, 1, A[1]) cout << 'D'; rep(i, 1, A[0]) cout << 'U';
                }
                cout << endl;

                continue;
            }
            if (!A[2]) {
                cout << "Impossible" << endl;
                continue;
            }
            cout << 'L';
            shang();
            rep(i, 2, A[2]) cout << 'L';
            rep(i, 1, A[3]) cout << 'R';
            cout << endl;
            continue;
        }


    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4032kb

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
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
UUUDDDL
UUDDRR...

result:

wrong answer case 22, participant does not find an answer but the jury does