QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506393 | #6422. Evil Coordinate | 122 | WA | 0ms | 3588kb | C++14 | 3.3kb | 2024-08-05 17:09:01 | 2024-08-05 17:09:01 |
Judging History
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: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible UUU
result:
wrong answer case 5, participant's output goes through forbidden coordinate