QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685185 | #6422. Evil Coordinate | adivse# | AC ✓ | 14ms | 4028kb | C++20 | 4.8kb | 2024-10-28 18:09:40 | 2024-10-28 18:09:41 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename T>
void cc(vector<T> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void cc(int a) { cout << a << endl; }
void cc(int a, int b) { cout << a << ' ' << b << endl; }
void cc(int a, int b, int c) { cout << a << ' ' << b << ' ' << c << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
void cmax(int& a, const int b) { if (b > a) a = b; }
void cmin(int& a, const int b) { if (b < a) a = b; }
using PII = pair<int, int>;
using i128 = __int128;
//--------------------------------------------------------------------------------
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int zx, zy;
int tx, ty;
int A[4];//0 shang 1 xia 2 zuo 3 you
//--------------------------------------------------------------------------------
void shang() {
rep(i, 1, A[0]) cout << 'U';
rep(i, 1, A[1]) cout << 'D';
}
void zuo() {
rep(i, 1, A[2]) cout << 'L';
rep(i, 1, A[3]) cout << 'R';
}
signed main() {
kuaidu();
T = 1;
cin >> T;
while (T--) {
cin >> zx >> zy;
string s; cin >> s;
rep(i, 0, 3) A[i] = 0;
tx = 0, ty = 0;
rep(i, 0, s.size() - 1) {
if (s[i] == 'U') A[0]++, ty += 1;
if (s[i] == 'L') A[2]++, tx -= 1;
if (s[i] == 'D') A[1]++, ty -= 1;
if (s[i] == 'R') A[3]++, tx += 1;
}
if (zx == 0 and zy == 0) {
cout << "Impossible" << endl;
continue;
}
if (zx == tx and zy == ty) {
cout << "Impossible" << endl;
continue;
}
if (zx and zy) {
if (ty == zy) {
zuo(), shang();
cout << endl;
continue;
}
if (tx == zx) {
shang(), zuo();
cout << endl;
continue;
}
shang(); zuo();
cout << endl;
continue;
}
if (tx and ty) {
if (zx == 0) {
zuo(), shang();
cout << endl;
continue;
}
if (zy == 0) {
shang(); zuo();
cout << endl;
continue;
}
continue;
}
if (zx and ty or zy and tx) {
if (zx and ty) {
shang(), zuo();
cout << endl;
continue;
}
if (zy and tx) {
zuo(), shang();
cout << endl;
continue;
}
}
if (zx) {
if (zx * tx > 0 and abs(zx) > abs(tx) || zx * tx <= 0) {
if (zx < 0) {
shang();
rep(i, 1, A[3]) cout << 'R';
rep(i, 1, A[2]) cout << 'L';
}
if (zx > 0) {
shang();
rep(i, 1, A[2]) cout << 'L';
rep(i, 1, A[3]) cout << 'R';
}
cout << endl;
continue;
}
if (!A[0]) {
cout << "Impossible" << endl;
continue;
}
//0 shang 1 xia 2 zuo 3 you
cout << 'U';
zuo();
rep(i, 2, A[0]) cout << 'U';
rep(i, 1, A[1]) cout << 'D';
cout << endl;
continue;
}
if (zy) {
if (zy * ty > 0 and abs(zy) > abs(ty) or zy * ty <= 0) {
if (zy < 0) {
zuo();
rep(i, 1, A[0]) cout << 'U';
rep(i, 1, A[1]) cout << 'D';
}
if (zy > 0) {
zuo();
rep(i, 1, A[1]) cout << 'D'; rep(i, 1, A[0]) cout << 'U';
}
cout << endl;
continue;
}
if (!A[2]) {
cout << "Impossible" << endl;
continue;
}
cout << 'L';
shang();
rep(i, 2, A[2]) cout << 'L';
rep(i, 1, A[3]) cout << 'R';
cout << endl;
continue;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 8ms
memory: 4028kb
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:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 14ms
memory: 3900kb
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