QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506329 | #6422. Evil Coordinate | Poknik | WA | 14ms | 3752kb | C++14 | 1.4kb | 2024-08-05 16:45:50 | 2024-08-05 16:45:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int x, y;
string s;
int flag = 0;
int dir[5];
int ds[4] = { 1, 2, 3, 4 };
char dp[5] = { '0', 'R', 'L', 'U', 'D' };
bool check() {
int x1 = 0, y1 = 0;
if (x == 0 && y == 0)return false;
for (int i = 0; i <= 3; i++) {
if (ds[i] == 1) {
if (y1 == y && x1 <= x && x1 + dir[1] >= x) return false;
x1 += dir[1];
}
if (ds[i] == 2) {
if (y1 == y && x1 >= x && x1 - dir[2] <= x) return false;
x1 -= dir[2];
}
if (ds[i] == 3) {
if (x1 == x && y1 <= y && y1 + dir[3] >= y) return false;
y1 += dir[3];
}
if (ds[i] == 4) {
if (x1 == x && y1 >= y && y1 - dir[4] <= y) return false;
y1 -= dir[4];
}
}
return true;
}
void solve() {
flag = 0;
cin >> x >> y;
cin >> s;
dir[1] = count(s.begin(), s.end(), 'R');
dir[2] = count(s.begin(), s.end(), 'L');
dir[3] = count(s.begin(), s.end(), 'U');
dir[4] = count(s.begin(), s.end(), 'D');
do {
if (check()) {
flag = 1;
for (int i = 0; i <= 3; i++) {
for (int j = 0; j < dir[ds[i]]; j++)
cout << dp[ds[i]];
}
break;
}
} while (next_permutation(ds+1, ds + 4));
if (!flag)
cout << "Impossible";
cout << endl;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
RRLLUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 3752kb
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:
RRUUDD RUU Impossible Impossible Impossible RRUUUUUUD RRRRLDD UD Impossible RRLLLLDD RRLLUDDD Impossible RUUDDDDLL LL Impossible RRLUUUD Impossible Impossible Impossible RRRLLLLLDD Impossible RL Impossible Impossible Impossible Impossible Impossible RRRRRLLLUU LLLUD Impossible LUUUDDD RRUUDD Impossi...
result:
wrong answer case 42, participant does not find an answer but the jury does