QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642396 | #6422. Evil Coordinate | SSAABBEERR | AC ✓ | 16ms | 3748kb | C++20 | 6.0kb | 2024-10-15 13:52:39 | 2024-10-15 13:52:42 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
using namespace std;
const int N = 1e6 + 10;
int n, m;
int tx, ty;
string s;
int c[4];
void solve()
{
cin >> tx >> ty >> s;
n = s.size();
s = " " + s;
rep(i, 0, 3) c[i] = 0;
rep(i, 1, n)
{
if(s[i] == 'L') c[0] ++ ;
else if(s[i] == 'R') c[1] ++ ;
else if(s[i] == 'U') c[2] ++ ;
else c[3] ++ ;
}
int xx = 0, yy = 0;
xx -= c[0];
xx += c[1];
yy += c[2];
yy -= c[3];
// cout<<xx<<" "<<yy<<endl;
if(xx == tx && yy == ty)
{
cout << "Impossible";
}
else if(!tx && !ty)
{
cout << "Impossible";
}
else if(yy != ty)
{
if(tx != 0)
{
while(c[2] -- ) cout << "U";
while(c[3] -- ) cout << "D";
while(c[0] -- ) cout << "L";
while(c[1] -- ) cout << "R";
}
else
{
if(xx != 0)
{
while(c[0] -- ) cout << "L";
while(c[1] -- ) cout << "R";
while(c[2] -- ) cout << "U";
while(c[3] -- ) cout << "D";
}
else
{
if(c[0])
{
while(c[0] -- ) cout << "L";
while(c[2] -- ) cout << "U";
while(c[3] -- ) cout << "D";
while(c[1] -- ) cout << "R";
}
else if(c[1])
{
while(c[1] -- ) cout << "R";
while(c[2] -- ) cout << "U";
while(c[3] -- ) cout << "D";
while(c[0] -- ) cout << "L";
}
else
{
if(min(0ll, yy) <= ty && max(0ll, yy) >= ty)
{
cout << "Impossible";
}
else
{
if(yy != 0)
{
if(yy > 0)
{
int f = 0;
while(c[2] || c[3])
{
if(!f && c[2]) cout << "U", c[2] -- ;
else if(f && c[3]) cout << "D", c[3] -- ;
else if(c[2]) cout << "U", c[2] -- ;
else cout << "D", c[3] -- ;
f ^= 1;
}
}
else
{
int f = 0;
while(c[2] || c[3])
{
if(f && c[2]) cout << "U", c[2] -- ;
else if(!f && c[3]) cout << "D", c[3] -- ;
else if(c[2]) cout << "U", c[2] -- ;
else cout << "D", c[3] -- ;
f ^= 1;
}
}
}
else
{
if(ty > 0) while(c[2] -- ) cout << "DU";
else while(c[3] -- ) cout << "UD";
}
}
}
}
}
}
else if(yy == ty)
{
if(ty != 0)
{
while(c[0] -- ) cout << "L";
while(c[1] -- ) cout << "R";
while(c[2] -- ) cout << "U";
while(c[3] -- ) cout << "D";
}
else
{
if(c[2])
{
while(c[2] -- ) cout << "U";
while(c[0] -- ) cout << "L";
while(c[1] -- ) cout << "R";
while(c[3] -- ) cout << "D";
}
else if(c[3])
{
while(c[3] -- ) cout << "D";
while(c[0] -- ) cout << "L";
while(c[1] -- ) cout << "R";
while(c[2] -- ) cout << "U";
}
else if(min(0ll, xx) <= tx && max(0ll, xx) >= tx)
{
cout << "Impossible";
}
else
{
if(xx != 0)
{
if(xx < 0)
{
int f = 0;
while(c[0] || c[1])
{
if(!f && c[0]) cout << "L", c[0] -- ;
else if(f && c[1]) cout << "R", c[1] -- ;
else if(c[0]) cout << "L", c[0] -- ;
else cout << "R", c[1] -- ;
f ^= 1;
}
}
else
{
int f = 0;
while(c[0] || c[1])
{
if(f && c[0]) cout << "L", c[0] -- ;
else if(!f && c[1]) cout << "R", c[1] -- ;
else if(c[0]) cout << "L", c[0] -- ;
else cout << "R", c[1] -- ;
f ^= 1;
}
}
}
else
{
if(tx < 0) while(c[0] -- ) cout << "RL";
else while(c[0] -- ) cout << "LR";
}
}
}
}
cout << endl;
}
signed main()
{
IOS;
int _;
_ = 1;
cin >> _;
while(_--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
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: 16ms
memory: 3748kb
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:
UURRDD 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 UUULDDD UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 15ms
memory: 3700kb
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 LRLR R LRLRLRLR ULR DU ULLRR DUDUDUDU ULLLLRRRR LRLR ULR R RUUUDDD DUDUDUDU DUDUDU LRLRLRLRLR LRLRLR ULR U LRLRLRLR RUUUUDDDD RUUUDDD LRLRLR DUDUDUDU R DUDUDU DUDUDU LRLRLRLRLR DUDUDUDU DUDU ULLLLRRRR DUDU LRLRLR ULR ULR U ULR LRLRLR LRLRLRLRLR U DUDUDU R LRLRLR RUUUUDDDD RUUUUDDDD LRLRLR ...
result:
ok 11107 cases