QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506459 | #6422. Evil Coordinate | Grunray | AC ✓ | 14ms | 3776kb | C++20 | 6.2kb | 2024-08-05 17:40:54 | 2024-08-05 17:40:54 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#define itn int
#define PII pair<int, int>
#define PLI pair<long long, int>
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#include<bits/stdc++.h>
#include<unordered_map>
using ll = long long;
using ldou = long double;
using unll = unsigned long long;
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) { f = ch != '-'; ch = getchar(); }
while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return f ? x : -x;
}
ll gcd(ll a, ll b) { // 最大公约数
while (b ^= a ^= b ^= a %= b)
;
return a;
}
ll lcm(ll a, ll b) { // 最小公倍数
return a / gcd(a, b) * b;
}
ll qmi(ll m, ll k, ll p) { // 快速幂
//求 m^k mod p,时间复杂度 O(logk)。
//m为底数,k为幂
ll res = 1 % p, t = m;
while (k) {
if (k & 1) res = res * t % p;
t = t * t % p;
k >>= 1;
}
return res;
}
unll qmi(unll m, unll k, unll p) { //龟速乘
ll res = 0, t = m;
while (k) {
if (k & 1) res = (res + t) % p;
k >>= 1;
t = (t << 1) % p;
}
return res;
}
////////////////////////////////////////////////////////////////////////////////
ll n, m, k;
const int N = 1000010;
const int M = 2e5 + 50;
const ll INF = 0x3f3f3f3f;
const ll MODE = ll(998244353);
const double Pi = 3.1415926;
const double eps = 1e-8;
const int dx[4] = { 1,-1, 0, 0 };
const int dy[4] = { 0, 0, 1,-1 };
//priority_queue<int> p;//这是一个大根堆q
//priority_queue<int, vector<int>, greater<int> >q;//这是一个小根堆q
//priority_queue<ll, vector<ll>, greater<ll> >pq; // 小根
ll a[5];
string str;
void solve() {
ll edx = 0, edy = 0;
ll x, y;
cin >> x >> y;
cin >> str;
memset(a, 0, sizeof(a));
if (x == 0 && y == 0) {
cout << "Impossible" << '\n';
return;
}
for (int i = 0; i < str.size(); i++)
{
if (str[i] == 'U') a[0]++;
if (str[i] == 'D') a[1]++;
if (str[i] == 'L') a[2]++;
if (str[i] == 'R') a[3]++;
}
edx = a[3] - a[2];
edy = a[0] - a[1];
if (edy == y && edx == x) {
cout << "Impossible" << '\n';
return;
}
if (a[2] == 0 && a[3] == 0)
{
if (x != 0) {
cout << str << '\n';
return;
}
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\n";
return;
}
else if (edy >= 0 && edy >= y)
{
if (0 <= y) {
cout << "Impossible\n";
return;
}
else {
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
cout << '\n';
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';
cout << '\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';
cout << '\n';
return;
}
else {
cout << "Impossible" << '\n';
return;
}
}
else if (a[0] == 0 && a[1] == 0)
{
if (y != 0) {
cout << str << '\n';
return;
}
if (x <= 0 && edx <= x)
{
cout << "Impossible" << '\n';
return;
}
else if (edx >= 0 && edx >= x) {
if (0 <= x) {
cout << "Impossible" << '\n';
return;
}
else {
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}
}
else if (x > edx && x >= 0) {
for (int i = 1; i <= a[2]; i++) cout << 'L';
for (int i = 1; i <= a[3]; i++) cout << 'R';
cout << '\n';
}
/*else if (edx >= 0 && edx >= x)
{
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}*/
else if (edx <= 0 && edx > x) {
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}
else {
cout << "Impossible" << '\n';
return;
}
}
else {
if (edx == x)
{
if (x == 0) {
if (a[2] != 0) {
cout << 'L';
--a[2];
}
else if (a[3] != 0) {
cout << 'R';
--a[3];
}
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
else {
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
}
else if (edy == y)
{
if (y == 0)
{
if (a[0] != 0) {
cout << 'U';
--a[0];
}
else if (a[1] != 0) {
cout << 'D';
--a[1];
}
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
else
{
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
}
else
{
if (x == 0) {
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
else {
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
}
}
}
signed main() {
std::ios::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0);
/*freopen("out.txt", "r", stdin);
freopen("wrt.txt", "w", stdout);*/
int TTT = 1; cin >> TTT;
while (TTT--) {
solve();
}
/*while (cin >> n >> m) {
solve();
}*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 13ms
memory: 3692kb
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:
URRUDD UUR Impossible Impossible Impossible RRUUUUUUD DDLRRRR UD Impossible LLLLRRDD LLRRUDDD Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU UDLLL Impossible ULUUDDD UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 14ms
memory: 3776kb
input:
11107 1 0 LLRLRURLR 1 0 LLRR 0 1 R 1 0 LLLRLRRR 1 0 RUL 0 1 UD 1 0 RLRLU 0 1 DDDUUUDU 1 0 RURRLLRLL 1 0 LRLR 1 0 ULR 0 1 R 0 1 DDUUUDR 0 1 UUDDUDDU 0 1 DDUUDU 1 0 RRLRLLRLRL 1 0 RLRRLL 1 0 LUR 1 0 U 1 0 LRRRLLLR 0 1 DRUUDDUDU 0 1 DUUDDUR 1 0 LRLRLR 0 1 UUDDDUDU 0 1 R 0 1 UDUDDU 0 1 DUUDUD 1 0 RRLRRR...
output:
ULLLLRRRR LLRR R LLLLRRRR ULR DU ULLRR DDDDUUUU ULLLLRRRR LLRR ULR R RUUUDDD DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR ULR U LLLLRRRR RUUUUDDDD RUUUDDD LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU ULLLLRRRR DDUU LLLRRR ULR ULR U ULR LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR RUUUUDDDD RUUUUDDDD LLLRRR ...
result:
ok 11107 cases