QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506423 | #6422. Evil Coordinate | buzhijingdi | AC ✓ | 24ms | 3748kb | C++14 | 1.9kb | 2024-08-05 17:21:27 | 2024-08-05 17:21:27 |
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 && x <= 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: 3556kb
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: 0
Accepted
time: 18ms
memory: 3680kb
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 UUUUUUDRR DDLRRRR UD Impossible DDLLLLRR UDDDLLRR Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLDDRRR Impossible LR Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 24ms
memory: 3748kb
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 DDDUUUR DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR ULR U LLLLRRRR DDDDUUUUR DDDUUUR LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU ULLLLRRRR DDUU LLLRRR ULR ULR U ULR LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR DDDDUUUUR DDDDUUUUR LLLRRR ...
result:
ok 11107 cases