QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506017 | #6422. Evil Coordinate | Umok | WA | 0ms | 3824kb | C++20 | 3.0kb | 2024-08-05 14:43:22 | 2024-08-05 14:43:23 |
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 ar[N];
int l, r, d, u, a, b;
void solve()
{
l = d = r = u = 0;
string s;
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++;
}
PII pot = {l + r, u + d};
if (pot.first == a && pot.second == b || a == 0 && b == 0)
{
cout << "Impossible" << endl;
return;
}
int x = r - l, y = u - d;
if (x == a || y == b)
{
if (x == 0 && y >= b && b > 0 || x == 0 && u - d <= b && b < 0)
{
cout << "Impossible" << endl;
return;
}
if (y == 0 && r - l >= a && a > 0 || y == 0 && r - l < a && a < 0)
{
cout << "Impossible" << endl;
return;
}
}
if (a == x)
{
if (b > 0)
{
for (int i = 1; i <= d; i++)
cout << "D";
for (int i = 1; i <= u; i++)
cout << "U";
}
else
{
for (int i = 1; i <= u; i++)
cout << "U";
for (int i = 1; i <= d; i++)
cout << "D";
}
if (a > 0)
{
for (int i = 1; i <= r; i++)
cout << "R";
for (int i = 1; i <= l; i++)
cout << "L";
}
else
{
for (int i = 1; i <= l; i++)
cout << "L";
for (int i = 1; i <= r; i++)
cout << "R";
}
}
else if (b == y)
{
if (a > 0)
{
for (int i = 1; i <= r; i++)
cout << "R";
for (int i = 1; i <= l; i++)
cout << "L";
}
else
{
for (int i = 1; i <= l; i++)
cout << "L";
for (int i = 1; i <= r; i++)
cout << "R";
}
if (b > 0)
{
for (int i = 1; i <= d; i++)
cout << "D";
for (int i = 1; i <= u; i++)
cout << "U";
}
else
{
for (int i = 1; i <= u; i++)
cout << "U";
for (int i = 1; i <= d; i++)
cout << "D";
}
}
else
{
for (int i = 1; i <= l; i++)
cout << "L";
for (int i = 1; i <= r; i++)
cout << "R";
for (int i = 1; i <= u; i++)
cout << "U";
for (int i = 1; i <= d; i++)
cout << "D";
}
cout << 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: 3824kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
Impossible UUU Impossible Impossible Impossible
result:
wrong answer case 1, participant does not find an answer but the jury does