QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506364 | #6422. Evil Coordinate | buzhijingdi | WA | 11ms | 3880kb | C++14 | 5.4kb | 2024-08-05 16:57:03 | 2024-08-05 16:57:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 5;
map<char, int> mp, mp2;
string s;
char ans[maxn];
int cnt;
void solve()
{
int x, y, ansx = 0, ansy = 0;
cin >> x >> y;
cin >> s;
mp.clear();
if (x == 0 && y == 0) {
cout << "Impossible" << endl;
return;
}
for (int i = 0; i < s.size(); i++) {
mp[s[i]]++;
}
int dx = 0, dy = 0;
dy += mp['U'];
dy -= mp['D'];
dx += mp['R'];
dx -= mp['L'];
if (dx == x && dy == y) {
cout << "Impossible" << endl;
return;
}
if ((mp['U'] == 0 && mp['D'] == 0)) {
if (x >= 0) {
if (mp['L'] >= mp['R']) { //先左后右
for (int i = 1; i <= mp['L']; i++) {
cout << "L";
}
for (int i = 1; i <= mp['R']; i++) {
cout << "R";
}
cout << endl;
return;
}
else {
if (mp['R'] - mp['L'] >= x) {
cout << "Impossible" << endl;
return;
}
else { // 先左
for (int i = 1; i <= mp['L']; i++) {
cout << "L";
}
for (int i = 1; i <= mp['R']; i++) {
cout << "R";
}
cout << endl;
return;
}
}
}
else {
if (mp['L'] <= mp['R']) { //先右
for (int i = 1; i <= mp['R']; i++) {
cout << "R";
}
for (int i = 1; i <= mp['L']; i++) {
cout << "L";
}
cout << endl;
return;
}
else {
if (mp['R'] - mp['L'] <= x) {
cout << "Impossible" << endl;
return;
}
else { // 先右
for (int i = 1; i <= mp['R']; i++) {
cout << "R";
}
for (int i = 1; i <= mp['L']; i++) {
cout << "L";
}
cout << endl;
return;
}
}
}
}
if ((mp['L'] == 0 && mp['R'] == 0)) {
if (y >= 0) {
if (mp['D'] >= mp['U']) { //先左后右
for (int i = 1; i <= mp['D']; i++) {
cout << "D";
}
for (int i = 1; i <= mp['U']; i++) {
cout << "U";
}
cout << endl;
return;
}
else {
if (mp['U'] - mp['D'] >= y) {
cout << "Impossible" << endl;
return;
}
else { // 先左
for (int i = 1; i <= mp['D']; i++) {
cout << "D";
}
for (int i = 1; i <= mp['U']; i++) {
cout << "U";
}
cout << endl;
return;
}
}
}
else {
if (mp['D'] <= mp['U']) { //先右
for (int i = 1; i <= mp['U']; i++) {
cout << "U";
}
for (int i = 1; i <= mp['D']; i++) {
cout << "D";
}
cout << endl;
return;
}
else {
if (mp['U'] - mp['D'] <= y) {
cout << "Impossible" << endl;
return;
}
else {
for (int i = 1; i <= mp['U']; i++) {
cout << "U";
}
for (int i = 1; i <= mp['D']; i++) {
cout << "D";
}
cout << endl;
return;
}
}
}
}
cnt = 0;
if (x >= 0) {
for (int i = 1; i <= mp['L']; i++) {
ans[++cnt] = 'L';
}
}
else {
for (int i = 1; i <= mp['R']; i++) {
ans[++cnt] = 'R';
}
}
if (y >= 0) {
for (int i = 1; i <= mp['D']; i++) {
ans[++cnt] = 'D';
}
}
else {
for (int i = 1; i <= mp['U']; i++) {
ans[++cnt] = 'U';
}
}
if (x >= 0) {
for (int i = 1; i <= mp['R']; i++) {
ans[++cnt] = 'R';
}
}
else {
for (int i = 1; i <= mp['L']; i++) {
ans[++cnt] = 'L';
}
}
if (y >= 0) {
for (int i = 1; i <= mp['U']; i++) {
ans[++cnt] = 'U';
}
}
else {
for (int i = 1; i <= mp['D']; i++) {
ans[++cnt] = 'D';
}
}
for (int i = 1; i <= cnt; i++) {
cout << ans[i];
}
cout << endl;
}
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: 3636kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLDRRUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 3880kb
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:
DDRRUU RUU Impossible Impossible Impossible RRDUUUUUU RRRRDDL DU Impossible LLLLRRDD LLURRDDD Impossible RDDDDLLUU LL Impossible LDRRUUU Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU ULLLD Impossible DDDLUUU UURRDD Impossi...
result:
wrong answer case 47, participant's output goes through forbidden coordinate