QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506415 | #6422. Evil Coordinate | buzhijingdi | WA | 12ms | 3836kb | C++14 | 1.9kb | 2024-08-05 17:17:09 | 2024-08-05 17:17:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[6];
string s;
void solve()
{
int x, y, u, d, l, r;
u = d = l = r = 0;
//memset(a,0,sizeof a);
for (int i = 1; i <= 4; i++) {
a[i] = i;
}
bool f = false;
cin >> x >> y >> s;
if (x == 0 && y == 0) {
cout << "Impossible" << endl;
return;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'U') {
u++;
}
if (s[i] == 'D') {
d++;
}
if (s[i] == 'R') {
r++;
}
if (s[i] == 'L') {
l++;
}
}
while (true) {
int xx = 0, yy = 0;
bool flag = true;
for (int i = 1; i <= 4; i++) {
if (a[i] == 1 && xx == x && y >= yy && y <= yy + u) {
flag = false;
break;
}
if (a[i] == 2 && xx == x && y >= yy - d && y <= yy) {
flag = false;
break;
}
if (a[i] == 3 && yy == y && x >= xx - l && x <= xx) {
flag = false;
break;
}
if (a[i] == 4 && yy == y && y <= xx + r && x >= xx) {
flag = false;
break;
}
if (a[i] == 1) {
yy += u;
}
else if (a[i] == 2) {
yy -= d;
}
else if (a[i] == 3) {
xx -= l;
}
else if (a[i] == 4) {
xx += r;
}
}
if (flag) {
for (int i = 1; i <= 4; i++) {
if (a[i] == 1) {
for (int j = 1; j <= u; j++) {
cout << "U";
}
}
if (a[i] == 2) {
for (int j = 1; j <= d; j++) {
cout << "D";
}
}
if (a[i] == 3) {
for (int j = 1; j <= l; j++) {
cout << "L";
}
}
if (a[i] == 4) {
for (int j = 1; j <= r; j++) {
cout << "R";
}
}
}
cout << endl;
f = true;
break;
}
if (!next_permutation(a + 1, a + 5)) {
break;
}
}
if (!f) {
cout << "Impossible" << endl;
return;
}
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
UUDLLRR UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 3836kb
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 UUUULLDDDR UUUUUUDRR DDLRRRR UD Impossible LLLLRRDD ULLRRDDD Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLRRRDD LLLLURRRR LR Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU UDLLL Impossible UUUDDDL UUDDRR Impossib...
result:
wrong answer case 5, participant's output goes through forbidden coordinate