QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506724#6422. Evil CoordinatemmzskmWA 27ms3832kbC++201.5kb2024-08-05 20:56:022024-08-05 20:56:02

Judging History

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

  • [2024-08-05 20:56:02]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3832kb
  • [2024-08-05 20:56:02]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<map>

using namespace std;
int mx, my;
int a[4] = { 0,1,2,3 };//U D L R
int cnt[4] = { 0 };
int op[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
bool check() {
	int x = 0, y = 0;
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < cnt[a[i]]; j++)
		{
			x += op[a[i]][0];
			y += op[a[i]][1];
			if (x == mx && y == my)  return false;
		}
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	map<int, string>mp;
	mp[0] = 'U', mp[1] = 'D', mp[2] = 'L', mp[3] = 'R';
	while (t--) 
	{
		cin >> mx >> my;
		string s;
		cin >> s;
		int x = 0, y = 0;
		memset(cnt, 0, sizeof(cnt));
		a[0] = 0, a[1] = 1, a[2] = 2, a[3] = 3;
		for (int i = 0; i < s.size(); i++) 
		{
			if (s[i] == 'U')
			{
				cnt[0]++;
			}
			if (s[i] == 'D')
			{
				cnt[1]++;
			}
			if (s[i] == 'L')
			{
				cnt[2]++;
			}
			if (s[i] == 'R')
			{
				cnt[3]++;
			}
		}
		if ((mx == 0 && my == 0) || (x == abs(cnt[2] - cnt[3]) && y == abs(cnt[0] - cnt[1])))
		{
			cout << "Impossible\n";
			continue;
		}
		bool ok = false;
			do {
				if (check())
				{
					ok = true;
					for (int i = 0; i < 4; i++)
					{
						for (int j = 0; j < cnt[a[i]]; j++)
							cout << mp[a[i]];
					}
					cout << endl;
					break;
				}
			} while (next_permutation(a, a + 4));
		if (!ok)
		{
			cout << "Impossible\n";
		}
	}

	return 0;
}

詳細信息

Test #1:

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

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: 27ms
memory: 3832kb

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
Impossible
Impossible
DDLLLLRR
UDDDLLRR
Impossible
UUDDDDLLR
LL
Impossible
UUUDLRR
Impossible
Impossible
Impossible
LLLLLDDRRR
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
UUUDDD...

result:

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