QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506287 | #6422. Evil Coordinate | lgxsx | WA | 23ms | 3864kb | C++14 | 3.6kb | 2024-08-05 16:27:21 | 2024-08-05 16:27:22 |
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;
int len = str.size();
string path;
if (x == 0 && y == 0)
{
cout << "Impossible"<<endl;
continue;
}
if (up + down == y&&left+right==x)
{
cout << "Impossible"<<endl;
continue;
}
if ((up >= y && down == 0 && left == 0 && right == 0 )||
(down <= y && up == 0 && left == 0 && right == 0) ||
(left <= x && down == 0 && up == 0 && right == 0) ||
(right >=x && up == 0 && down == 0 && left == 0))
{
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;
}
}
}
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: 3468kb
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: 3864kb
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