QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506295#6422. Evil Coordinate122WA 23ms3708kbC++143.3kb2024-08-05 16:29:122024-08-05 16:29:13

Judging History

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

  • [2024-08-05 16:29:13]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3708kb
  • [2024-08-05 16:29:12]
  • 提交

answer

#include <iostream> 
#include<vector>
#include<string>
#include<algorithm>
#include <cstring>
#include<ctype.h>
#include<set>
#include<map>
#include<cmath>
#include<climits>
#include<stack>
#include<list>
#include<queue>
#include<unordered_map>
#include<unordered_set>
#define IOS ios::sync_with_stdio(false);cin.tie(0); 
#define maxn 100+5
#define ll long long
using namespace std;
const int mod = 1e8;


signed main() {
	int t;
	cin >> t;
	string s = "UDLR";
	while (t--)
	{
		int x, y;
		vector<int>cnt(5, 0);
		cin >> x >> y;
		string str;
		cin >> str;
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] == s[0])
				cnt[0]++;
			if (str[i] == s[1])
				cnt[1]++;
			if (str[i] == s[2])
				cnt[2]++;
			if (str[i] == s[3])
				cnt[3]++;
		}
		int up = cnt[0]; int down = cnt[1]; int left = cnt[2]; int right = cnt[3];
		down = -down; left = -left;
		string path;
		if (x == 0 && y == 0)  //在原点
		{
			cout << "Impossible"<<endl;
			continue;
		}
		if (up + down == y&&left+right==x)  //在终点
		{
			cout << "Impossible"<<endl;
			continue;
		}
		
		if (y == 0&&up==0&&down==0)
		{
			if (x > 0 && left + right >= x)
			{
				cout << "Impossible" << endl;
				continue;
			}
			else if (x < 0 && left + right <= x)
			{
				cout << "Impossible" << endl;
				continue;
			}
			else
			{
				if (x > 0)
				{
					while (left < 0)
					{
						left++;
						path.push_back(s[2]);
					}
					while (right)
					{
						right--;
						path.push_back(s[3]);
					}
					cout << path << endl;
					continue;
				}
				else
				{
					while (right)
					{
						right--;
						path.push_back(s[3]);
					}
					while (left < 0)
					{
						left++;
						path.push_back(s[2]);
					}
					cout << path << endl;
					continue;
				}
			}
		}
		if (x == 0 && left == 0 && right == 0)
		{
			if (y > 0 && up + down >= y)
			{
				cout << "Impossible" << endl;
				continue;
			}
			else if (y < 0 && up + down <= y)
			{
				cout << "Impossible" << endl;
				continue;
			}
			else
			{
				if (y > 0)
				{
					while (down < 0)
					{
						down++;
						path.push_back(s[1]);
					}
					while (up)
					{
						up--;
						path.push_back(s[0]);
					}
					cout << path << endl;
					continue;
				}
				else
				{
					while (up)
					{
						up--;
						path.push_back(s[0]);
					}
					while (down < 0)
					{
						down++;
						path.push_back(s[1]);
					}
					cout << path << endl;
					continue;
				}
			}
		}
		
		/*cout << up << " " <<down << endl;*/
		if (up + down != y)
		{
			while (up)
			{
				up--;
				path.push_back(s[0]);
			}
			while (down < 0)
			{
				down++;
				path.push_back(s[1]);
			}
			while (left<0)
			{
				left++;
				path.push_back(s[2]);
			}
			while (right)
			{
				right--;
				path.push_back(s[3]);
			}
			cout << path << endl;
			continue;
		}
		
		if (left + right != x)
		{
			while (left < 0)
			{
				left++;
				path.push_back(s[2]);
			}
			while (right)
			{
				right--;
				path.push_back(s[3]);
			}
			while (up)
			{
				up--;
				path.push_back(s[0]);
			}
			while (down < 0)
			{
				down++;
				path.push_back(s[1]);
			}

			cout << path << endl;
			continue;
		}
		else cout << "Impossible" << endl;

	}


}

详细

Test #1:

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

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: 23ms
memory: 3708kb

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:

RRUUDD
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
LUUUDDD
UUDDRR
Impossi...

result:

wrong answer case 35, participant's output goes through forbidden coordinate