QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506397 | #6422. Evil Coordinate | buzhijingdi | WA | 0ms | 3832kb | C++14 | 2.1kb | 2024-08-05 17:09:32 | 2024-08-05 17:09:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[6];
void solve()
{
int x, y, u, d, l, r;
u = d = l = r = 0;
string s;
//memset(a,0,sizeof a);
for (int i = 1; i <= 4; i++) {
a[i] = i;
}
bool f = false;
int ax = 0, ay = 0;
cin >> x >> y;
if (x == 0 && y == 0) {
cout << "Impossible" << endl;
return;
}
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'U') {
u++;
ax++;
}
if (s[i] == 'D') {
d++;
ax--;
}
if (s[i] == 'R') {
r++;
ay++;
}
if (s[i] == 'L') {
l++;
ay--;
}
}
if (ay == x &&ay == y) {
cout << "Impossible" << endl;
return;
}
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: 3816kb
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: 0ms
memory: 3832kb
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 Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Imp...
result:
wrong answer case 6, participant does not find an answer but the jury does