QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506654 | #6422. Evil Coordinate | mmzskm | WA | 15ms | 3772kb | C++20 | 2.2kb | 2024-08-05 20:27:58 | 2024-08-05 20:27:59 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define int long long
int cnt[4];
void solve()
{
fill(cnt, cnt + 4, 0);
int xx, yy;
string s;
cin >> xx >> yy >> s;
if (xx == 0 && yy == 0)
{
cout << "Impossible" << endl;
return;
}
for (int i = 0; i < s.length(); i++)
{
if (s[i] == 'U')
{
cnt[0]++;
}
else if (s[i] == 'D')
{
cnt[1]++;
}
else if (s[i] == 'L')
{
cnt[2]++;
}
else
{
cnt[3]++;
}
}
if (xx == abs(cnt[3] - cnt[2]) && yy == abs(cnt[0] - cnt[1]))
{
cout << "Impossible" << endl;
return;
}
string t = "UDLR";
int x, y, f;
do
{
f = 1;
x = 0, y = 0;
for (auto i : t)
{
switch (i)
{
case 'U':
for (int j = 0; j < cnt[0]; j++)
{
y++;
if (x == xx && y == yy)
{
f = 0;
break;
}
}
break;
case 'D':
for (int j = 0; j < cnt[1]; j++)
{
y--;
if (x == xx && y == yy)
{
f = 0;
break;
}
}
break;
case 'L':
for (int j = 0; j < cnt[2]; j++)
{
x--;
if (x == xx && y == yy)
{
f = 0;
break;
}
}
break;
case 'R':
for (int j = 0; j < cnt[3]; j++)
{
x++;
if (x == xx && y == yy)
{
f = 0;
break;
}
}
break;
default:
break;
}
}
if (!f)
{
break;
}
} while (!f && next_permutation(t.begin(), t.end()));//四个方向全排列
if (f)
{
for (auto i : t)
{
switch (i)
{
case 'U':
for (int j = 0; j < cnt[0]; j++)
{
cout << 'U';
}
break;
case 'D':
for (int j = 0; j < cnt[1]; j++)
{
cout << 'D';
}
break;
case 'L':
for (int j = 0; j < cnt[2]; j++)
{
cout << 'L';
}
break;
case 'R':
for (int j = 0; j < cnt[3]; j++)
{
cout << 'R';
}
break;
default:
break;
}
}
cout << endl;
}
else
{
cout << "Impossible" << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 15ms
memory: 3772kb
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 Impossible Impossible LR Impossible Impossible Impossible Impossible Impossible Impossible UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
wrong answer case 20, participant does not find an answer but the jury does