QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506453 | #6422. Evil Coordinate | Grunray | WA | 13ms | 3768kb | C++20 | 6.4kb | 2024-08-05 17:37:06 | 2024-08-05 17:37:06 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#define itn int
#define PII pair<int, int>
#define PLI pair<long long, int>
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#include<bits/stdc++.h>
#include<unordered_map>
using ll = long long;
using ldou = long double;
using unll = unsigned long long;
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) { f = ch != '-'; ch = getchar(); }
while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return f ? x : -x;
}
ll gcd(ll a, ll b) { // 最大公约数
while (b ^= a ^= b ^= a %= b)
;
return a;
}
ll lcm(ll a, ll b) { // 最小公倍数
return a / gcd(a, b) * b;
}
ll qmi(ll m, ll k, ll p) { // 快速幂
//求 m^k mod p,时间复杂度 O(logk)。
//m为底数,k为幂
ll res = 1 % p, t = m;
while (k) {
if (k & 1) res = res * t % p;
t = t * t % p;
k >>= 1;
}
return res;
}
unll qmi(unll m, unll k, unll p) { //龟速乘
ll res = 0, t = m;
while (k) {
if (k & 1) res = (res + t) % p;
k >>= 1;
t = (t << 1) % p;
}
return res;
}
////////////////////////////////////////////////////////////////////////////////
ll n, m, k;
const int N = 1000010;
const int M = 2e5 + 50;
const ll INF = 0x3f3f3f3f;
const ll MODE = ll(998244353);
const double Pi = 3.1415926;
const double eps = 1e-8;
const int dx[4] = { 1,-1, 0, 0 };
const int dy[4] = { 0, 0, 1,-1 };
//priority_queue<int> p;//这是一个大根堆q
//priority_queue<int, vector<int>, greater<int> >q;//这是一个小根堆q
//priority_queue<ll, vector<ll>, greater<ll> >pq; // 小根
ll a[5];
string str;
void solve() {
ll edx = 0, edy = 0;
ll x, y;
cin >> x >> y;
cin >> str;
memset(a, 0, sizeof(a));
for (int i = 0; i < str.size(); i++)
{
if (str[i] == 'U') a[0]++;
if (str[i] == 'D') a[1]++;
if (str[i] == 'L') a[2]++;
if (str[i] == 'R') a[3]++;
}
edx = a[3] - a[2];
edy = a[0] - a[1];
if (x == 0 && y == 0) {
cout << "Impossible" << '\n';
return;
}
else if (edy == y && edx == x) {
cout << "Impossible" << '\n';
return;
}
else if (a[2] == 0 && a[3] == 0)
{
if (x != 0) {
cout << str << '\n';
return;
}
else {
if (y > edy && y >= 0) {
for (int i = 0; i < a[1]; i++)cout << 'D';
for (int i = 0; i < a[0]; i++)cout << 'U';
cout << '\n';
return;
}
else if (y <= 0 && edy <= y)
{
cout << "Impossible" << '\n';
return;
}
else if (edy >= 0 && edy >= y && y >= 0)
{
if (0 <= y) {
cout << "Impossible" << '\n';
return;
}
else {
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
cout << '\n';
return;
}
}
/*else if (edy >= 0 && edy >= y)
{
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
cout << '\n';
return;
}*/
else if (y < edy && edy <= 0) {
for (int i = 1; i <= a[0]; i++) cout << 'U';
for (int i = 1; i <= a[1]; i++) cout << 'D';
cout << '\n';
return;
}
else {
cout << "Impossible" << '\n';
return;
}
}
}
else if (a[0] == 0 && a[1] == 0)
{
if (y != 0) {
cout << str << '\n';
return;
}
else {
if (x <= 0 && edx <= x)
{
cout << "Impossible" << '\n';
return;
}
else if (edx >= 0 && edx >= x && x >= 0) {
if (0 <= x) {
cout << "Impossible" << '\n';
return;
}
else {
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}
}
else if (x > edx && x >= 0) {
for (int i = 1; i <= a[2]; i++) cout << 'L';
for (int i = 1; i <= a[3]; i++) cout << 'R';
cout << '\n';
}
/*else if (edx >= 0 && edx >= x)
{
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}*/
else if (edx <= 0 && edx > x) {
for (int i = 1; i <= a[3]; i++) cout << 'R';
for (int i = 1; i <= a[2]; i++) cout << 'L';
cout << '\n';
return;
}
else {
cout << "Impossible" << '\n';
return;
}
}
}
else {
if (edx == x)
{
if (x == 0) {
if (a[2] != 0) {
cout << 'L';
--a[2];
}
else if (a[3] != 0) {
cout << 'R';
--a[3];
}
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
else {
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
}
else if (edy == y)
{
if (y == 0)
{
if (a[0] != 0) {
cout << 'U';
--a[0];
}
else if (a[1] != 0) {
cout << 'D';
--a[1];
}
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
else
{
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
}
else
{
if (x == 0) {
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
cout << '\n';
return;
}
else {
for (int i = 0; i < a[0]; i++) cout << "U";
for (int i = 0; i < a[1]; i++) cout << "D";
for (int i = 0; i < a[2]; i++) cout << "L";
for (int i = 0; i < a[3]; i++) cout << "R";
cout << '\n';
return;
}
}
}
}
signed main() {
std::ios::sync_with_stdio(false); std::cin.tie(0), std::cout.tie(0);
/*freopen("out.txt", "r", stdin);
freopen("wrt.txt", "w", stdout);*/
int TTT = 1; cin >> TTT;
while (TTT--) {
solve();
}
/*while (cin >> n >> m) {
solve();
}*/
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3768kb
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:
URRUDD UUR Impossible Impossible Impossible RRUUUUUUD DDLRRRR UD Impossible LLLLRRDD LLRRUDDD Impossible UUDDDDLLR LL Impossible UUUDLRR Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU UDLLL Impossible ULUUDDD UUDDRR Impossi...
result:
wrong answer case 61, participant does not find an answer but the jury does