QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589422#6422. Evil Coordinateji_114514AC ✓16ms3792kbC++201.4kb2024-09-25 17:48:222024-09-25 17:48:23

Judging History

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

  • [2024-09-25 17:48:23]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:3792kb
  • [2024-09-25 17:48:22]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 1e5 + 10;
int n, x, y;
string t = "LRDU", res, s;
map<char, int>ha;

int cnt[4];

void out(int i)
{
    while (cnt[i]--)cout << res[i];
}

void solve()
{
    cin >> x >> y >> s;
    res = t;
    for (int i = 0; i < 4; i++)cnt[i] = 0;
    for (auto k : s)cnt[ha[k]]++;
    if (x < 0)x = -x, swap(cnt[0], cnt[1]), swap(res[0], res[1]);
    if (y < 0)y = -y, swap(cnt[2], cnt[3]), swap(res[2], res[3]);
    if (-cnt[0] + cnt[1] == x && -cnt[2] + cnt[3] == y)cout << "Impossible\n";
    else if (x == 0 && y == 0)cout << "Impossible\n";
    else {
        if (cnt[1] - cnt[0] == x) {
            swap(cnt[0], cnt[2]), swap(cnt[1], cnt[3]), swap(x, y), swap(res[0], res[2]), swap(res[1], res[3]);
        }
        if (y == 0 && cnt[1] >= cnt[0] + x && cnt[2] == 0 && cnt[3] == 0)cout << "Impossible\n";
        else if (y == 0) {
            if (cnt[2])cnt[2]--, cout << res[2];
            else if (cnt[3])cnt[3]--, cout << res[3];
            for (int i = 0; i < 4; i++)out(i);
            cout << '\n';
        }
        else {
            for (int i = 0; i < 4; i++)out(i);
            cout << "\n";
        }
    }
}

int main()
{
    ha['L'] = 0, ha['R'] = 1, ha['D'] = 2, ha['U'] = 3;
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1; cin >> t;
    while (t--)solve();
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

LLRRDUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: 0
Accepted
time: 15ms
memory: 3792kb

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:

DRRDUU
URU
Impossible
Impossible
Impossible
RRDUUUUUU
RRRRLDD
DU
Impossible
LLLLRRDD
LLRRUDDD
Impossible
DDDDUURLL
LL
Impossible
DUUULRR
Impossible
Impossible
Impossible
LLLLLRRRDD
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
LLLUD
Impossible
DLDDUUU
UUDDRR
Impossi...

result:

ok 11109 cases

Test #3:

score: 0
Accepted
time: 16ms
memory: 3792kb

input:

11107
1 0
LLRLRURLR
1 0
LLRR
0 1
R
1 0
LLLRLRRR
1 0
RUL
0 1
UD
1 0
RLRLU
0 1
DDDUUUDU
1 0
RURRLLRLL
1 0
LRLR
1 0
ULR
0 1
R
0 1
DDUUUDR
0 1
UUDDUDDU
0 1
DDUUDU
1 0
RRLRLLRLRL
1 0
RLRRLL
1 0
LUR
1 0
U
1 0
LRRRLLLR
0 1
DRUUDDUDU
0 1
DUUDDUR
1 0
LRLRLR
0 1
UUDDDUDU
0 1
R
0 1
UDUDDU
0 1
DUUDUD
1 0
RRLRRR...

output:

ULLLLRRRR
LLRR
R
LLLLRRRR
ULR
DU
ULLRR
DDDDUUUU
ULLLLRRRR
LLRR
ULR
R
RDDDUUU
DDDDUUUU
DDDUUU
LLLLLRRRRR
LLLRRR
ULR
U
LLLLRRRR
RDDDDUUUU
RDDDUUU
LLLRRR
DDDDUUUU
R
DDDUUU
DDDUUU
LLLLLRRRRR
DDDDUUUU
DDUU
ULLLLRRRR
DDUU
LLLRRR
ULR
ULR
U
ULR
LLLRRR
LLLLLRRRRR
U
DDDUUU
R
LLLRRR
RDDDDUUUU
RDDDDUUUU
LLLRRR
...

result:

ok 11107 cases