QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506371 | #6422. Evil Coordinate | Grunray | WA | 0ms | 3548kb | C++20 | 2.8kb | 2024-08-05 16:59:06 | 2024-08-05 16:59:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e3 + 5;
int a[N];
int b[N]; int n, m;
int c[N];
int coun[N];
double l[N], r[N];
void solve()
{
int edx = 0, edy = 0;
int x, y;
cin >> x >> y;
string s;
cin >> s;
memset(a, 0, sizeof(a));
if (x == 0 && y == 0) {
cout << "Impossible" << endl;
return;
}
for (int i = 0; i < s.size(); i++)
{
if (s[i] == 'U') a[0]++;
if (s[i] == 'D') a[1]++;
if (s[i] == 'L') a[2]++;
if (s[i] == 'R') a[3]++;
}
edx = a[3] - a[2];
edy = a[0] - a[1];
if (edy == y && edx == x) {
cout << "Impossible" << endl;
return;
}
if ((a[2] == 0 && a[3] == 0))
{
if (x != 0) {
cout << s << '\n';
return;
}
else if (y > edy && y <= 0) {
for (int i = 0; i < a[1]; i++)cout << 'D';
for (int i = 0; i < a[0]; i++)cout << 'U';
cout << '\n';
return;
}
else if (y >= 0 && edy >= y)
{
cout << "Impossible" << endl;
return;
}
else if (edy >= 0 && edy <= y && y >= 0)
{
cout << "Impossible" << endl;
return;
}
else if (edy >= 0 && edy <= y)
{
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
printf("\n");
return;
}
else if (y < edy && edy <= 0) {
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
printf("\n");
return;
}
else {
cout << "Impossible" << endl;
return;
}
}
else if ((a[0] == 0 && a[1] == 0))
{
if (y != 0) {
cout << s << '\n';
return;
}
if (x >= 0 && edx >= x)
{
cout << "Impossible" << endl;
return;
}
if (x <= 0 && edx <= x)
{
cout << "Impossible" << endl;
return;
}
}
if (edy == y)
{
if (y == 0)
{
cout << "U";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[0] - 1; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
}
else
{
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[0]; i++) cout << "U";
}
}
else if (edx == x)
{
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[2]; i++) cout << "L";
}
else
{
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[0]; i++) cout << "U";
}
cout << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
RRLLDUU Impossible Impossible Impossible Impossible
result:
wrong answer case 2, participant does not find an answer but the jury does