QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507073 | #6422. Evil Coordinate | Umok | WA | 0ms | 3556kb | C++20 | 1.7kb | 2024-08-06 10:07:42 | 2024-08-06 10:07:43 |
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;
int ar[4] = {0, 1, 2, 3};
int cnt[4] = {0};
int op[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
map<int, char> mp;
bool check()
{
int x = 0, y = 0;
for (int i = 0; i < 4; i++)
for (int j = 0; j < cnt[ar[i]]; j++)
{
x += op[ar[j]][0];
y += op[ar[j]][1];
if (x == a && y == b)
return 0;
}
return 1;
}
void solve()
{
cin >> a >> b;
string s;
cin >> s;
int x = 0, y = 0;
memset(cnt, 0, sizeof cnt);
ar[0] = 0, ar[1] = 1, ar[2] = 2, ar[3] = 3;
for (char c : s)
{
if (c == 'U')
cnt[0]++, y++;
else if (c == 'D')
cnt[1]++, y--;
else if (c == 'L')
cnt[2]++, x--;
else if (c == 'R')
cnt[3]++, x++;
}
if (x == a && y == b || a == 0 && b == 0)
{
cout << "Impossible" << endl;
return;
}
bool ok = 0;
do
{
if (check())
{
ok = 1;
for (int i = 0; i < 4; i++)
for (int j = 0; j < cnt[ar[i]]; j++)
cout << mp[ar[i]];
break;
}
} while (next_permutation(ar, ar + 4));
if (!ok)
{
cout << "Impossible" << endl;
}
}
signed main()
{
mp[0] = 'U';
mp[1] = 'D';
mp[2] = 'L';
mp[3] = 'R';
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: 3556kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
UUDLLRRUUUImpossible UUUImpossible
result:
wrong answer Line "UUDLLRRUUUImpossible" doesn't correspond to pattern "[UDLR]{1,100000}|Impossible"