QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507053 | #6422. Evil Coordinate | Umok | WA | 0ms | 3616kb | C++20 | 3.0kb | 2024-08-06 09:37:51 | 2024-08-06 09:37:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
#define int long long
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
#define mod 10007
#define eps 1e-7
int l, r, d, u, a, b;
void solve()
{
l = d = r = u = 0;
string s, ans;
cin >> a >> b;
cin >> s;
for (char c : s)
{
if (c == 'L')
l++;
else if (c == 'R')
r++;
else if (c == 'U')
u++;
else
d++;
}
int x = r - l, y = u - d;
if (x == a && y == b || a == 0 && b == 0)
{
cout << "Impossible" << endl;
return;
}
if (u == 0 && d == 0 && a == 0)
{
if ((y >= b && b > 0) || (y <= b && b < 0))
{
cout << "Impossible" << endl;
return;
}
}
else if (l == 0 && r == 0 && b == 0)
{
if ((x >= a && a > 0) || (x <= a && a < 0))
{
cout << "Impossible" << endl;
return;
}
}
/////////**************************** */
if (b == 0)
{
if (u)
for (; u; u--)
ans += "U";
else if (d)
for (; d; d--)
ans += "D";
}
for (int i = 1; u && i < b; i++, u--)
ans += "U";
for (int i = 1; d && -i > b; i++, d--)
ans += "D";
if (a == 0)
{
if (l)
for (; l; l--)
ans += "L";
else if (r)
for (; r; r--)
ans += "R";
}
else if (a > 0)
{
for (; l; l--)
ans += "L";
}
else
for (; r; r--)
ans + "R";
// int mins = min(u, d);
// if (b > 0)
// for (int i = 1; i <= mins; i++)
// ans += "DU";
// else if (b < 0)
// for (int i = 1; i <= mins; i++)
// ans += "UD";
// u -= mins, d -= mins;
// mins = min(l, r);
// if (a > 0)
// for (int i = 1; i <= mins; i++)
// ans += "LR";
// else if (a < 0)
// for (int i = 1; i <= mins; i++)
// ans += "RL";
// l -= mins, r -= mins;
if (ans[0] == 'U')
for (int i = 1; i <= u; i++)
ans += "U";
else if (ans[0] == 'D')
for (int i = 1; i <= d; i++)
ans += "D";
if (ans.find('R') != -1)
for (int i = 1; i <= r; i++)
ans += "R";
else if (ans.find('L') != -1)
for (int i = 1; i <= l; i++)
ans += "L";
for (int i = 1; i <= r; i++)
ans += "R";
for (int i = 1; i <= d; i++)
ans += "D";
for (int i = 1; i <= u; i++)
ans += "U";
for (int i = 1; i <= l; i++)
ans += "L";
cout << ans << endl;
}
signed main()
{
IOS;
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRDUU UUU Impossible UUUUU Impossible
result:
wrong answer case 4, participant's output goes through forbidden coordinate