QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589397 | #6422. Evil Coordinate | ji_114514 | WA | 15ms | 3736kb | C++20 | 1.4kb | 2024-09-25 17:41:26 | 2024-09-25 17:41:27 |
Judging History
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 (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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
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: -100
Wrong Answer
time: 15ms
memory: 3736kb
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 DRUU Impossible Impossible RRDUUUUUU RRRRLDD DU Impossible LLLLRRDD LLRRUDDD Impossible DDDDUURLL LL Impossible DUUULRR DDDDDDDUUU Impossible Impossible LLLLLRRRDD Impossible RL D L DLRRRDDDUU DLUU Impossible LLLRRRRRUU LLLUD Impossible DLDDUUU UUDDRR Impossible DRRLDUU RRDDUUUUU RRRRRLUU...
result:
wrong answer case 3, participant's output goes through forbidden coordinate