QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506660#6422. Evil CoordinatemmzskmWA 8ms3844kbC++202.2kb2024-08-05 20:31:132024-08-05 20:31:13

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 20:31:13]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3844kb
  • [2024-08-05 20:31:13]
  • 提交

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;
}




詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

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: 8ms
memory: 3844kb

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
Impossible
UDLLL
Impossible
UUUDDDL
UUDDRR
Impossi...

result:

wrong answer case 28, participant does not find an answer but the jury does