QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506032 | #6422. Evil Coordinate | EdisonBa | WA | 23ms | 3860kb | C++14 | 6.8kb | 2024-08-05 14:48:02 | 2024-08-05 14:48:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re read()
#define INF 9223372036854775800
#define fr(i, x, y) for(int i = x, p = y; i <= p; ++i)
#define rp(i, x, y) for(int i = x, p = y; i >= p; --i)
#define Timeok ((double)clock() / CLOCKS_PER_SEC < MAX_TIME)
const double MAX_TIME = 1.0 - 0.0032;
inline ll read()
{
ll x = 0, f = 0;
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;
}
void write(ll x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
inline void W(ll x, char ch)
{
write(x);
putchar(ch);
}
/*------------C-O-D-E------------*/
const int N = 1e5 + 4;
ll n, m, T, x, y;
int r, u, l, d;
int main()
{
ll T = re;
while(T--)
{
x = re, y = re;
string s;
cin>>s;
if(x == 0 && y == 0)
{
puts("Impossible");
continue;
}
int len = s.size();
r = 0, u=0,l=0,d=0;
fr(i,0,len - 1)
{
if(s[i] == 'R') ++r;
if(s[i] == 'U') ++u;
if(s[i] == 'L') ++l;
if(s[i] == 'D') ++d;
}
ll nx = r - l, ny = u - d;
// cout<<nx<<' '<<ny<<endl;
if(nx == x && ny == y)
{
puts("Impossible");
continue;
}
// Imposs ud
if(l == 0 && r == 0)
{
if(ny > 0 && y > 0 && ny > y)
{
puts("Impossible");
continue;
}
if(ny < 0 && y < 0 && ny < y)
{
puts("Impossible");
continue;
}
if(y > 0)
{
fr(i,1,d) putchar('D');
fr(i,1,u) putchar('U');
puts("");
continue;
}
if(y < 0)
{
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
// continue;
}
// Imposs lr
if(u == 0 && d == 0)
{
if(nx > 0 && x > 0 && nx > x)
{
puts("Impossible");
continue;
}
if(nx < 0 && x < 0 && nx < x)
{
puts("Impossible");
continue;
}
if(x > 0)
{
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
if(x < 0)
{
fr(i,1,r) putchar('R');
fr(i,1,l) putchar('L');
puts("");
continue;
}
// continue;
}
// ud 1
if(x == 0 && nx == 0)
{
if(ny > 0 && y > 0 && ny > y)
{
if(l) { --l; putchar('L'); }
else { --r; putchar('R'); }
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
if(ny < 0 && y < 0 && ny < y)
{
if(l) { --l; putchar('L'); }
else { --r; putchar('R'); }
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
if(y > 0)
{
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,d) putchar('D');
fr(i,1,u) putchar('U');
puts("");
continue;
}
if(y < 0)
{
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
// continue;
}
// lr 1
if(y == 0 && ny == 0)
{
if(nx > 0 && x > 0 && nx > x)
{
if(u) { --u; putchar('U'); }
else { --d; putchar('D'); }
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
if(nx < 0 && x < 0 && nx < x)
{
if(u) { --u; putchar('U'); }
else { --d; putchar('D'); }
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
if(x > 0)
{
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
if(x < 0)
{
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,r) putchar('R');
fr(i,1,l) putchar('L');
puts("");
continue;
}
// continue;
}
if(ny == 0)
{
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
if(nx == 0)
{
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
if(ny == y)
{
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
puts("");
continue;
}
if(nx == x)
{
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
fr(i,1,u) putchar('U');
fr(i,1,d) putchar('D');
fr(i,1,l) putchar('L');
fr(i,1,r) putchar('R');
puts("");
continue;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: -100
Wrong Answer
time: 23ms
memory: 3860kb
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:
UUDDRR 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 UUUDDDL UUDDRR Impossi...
result:
wrong answer case 35, participant's output goes through forbidden coordinate