QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506370 | #6422. Evil Coordinate | Poknik | WA | 13ms | 3744kb | C++14 | 1.5kb | 2024-08-05 16:58:48 | 2024-08-05 16:58:49 |
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');
int xx=0,yy=0;
xx=xx-dir[2]+dir[1];
yy=yy-dir[4]+dir[3];
if(xx==x&&yy==y){
puts("Impossible");
}
else {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, 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: 3584kb
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: 13ms
memory: 3744kb
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 RRUUUUUUD RRRRLDD UD RRLLLLDD RRLLUDDD RUUDDDDLL LL RRUUUDL Impossible RRRLLLLLDD RL Impossible Impossible Impossible Impossible RRRRRLLLUU LLLUD LUUUDDD RRUUDD RRLUUDD RRUUUUUDD RRRRRLUUUD RRRLLD LLDDDDD RLLLUUDDDD Impossible RUD LLRRUUUUDD LLLUUUDD UUDDDDD UUULDD D...
result:
wrong answer case 5, participant's output is not a permutation of the input