QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506410 | #6422. Evil Coordinate | xixu | AC ✓ | 25ms | 3880kb | C++17 | 2.9kb | 2024-08-05 17:15:28 | 2024-08-05 17:15:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define int short
#define int long long
typedef long long ll;
int f = 0;
map<int , char> ump , uump;
void solve()
{
int x , y;
cin >> x >> y;
map<int , int> mp;
ump[1] = 'U';
ump[2] = 'D';
ump[3] = 'L';
ump[4] = 'R';
uump['U'] = 1;
uump['D'] = 2;
uump['L'] = 3;
uump['R'] = 4;
string s;
cin >> s;
for(int i = 0; s[i]; i ++)
{
mp[uump[s[i]]] ++;
}
vector<int> v;
for(int i = 1; i <= 4; i ++)
{
v.push_back(i);
}
int xx = 0 , yy = 0;
if(!x && !y)
{
cout << "Impossible\n";
return ;
}
int cnt = 0;
do
{
// ++ cnt;
xx = 0 , yy = 0 , f = 0;
for(int i = 0; i < v.size(); i ++)
{
if(v[i] == 1)
{
yy += mp[v[i]];
if(xx == x && ((abs(yy) >= abs(y) && ((yy >= 0 && y >= 0) || (yy < 0 && y < 0))) || yy == y))
{
f = 1;
continue ;
}
}
else if(v[i] == 2)
{
yy -= mp[v[i]];
if(xx == x && ((abs(yy) >= abs(y) && ((yy >= 0 && y >= 0) || (yy < 0 && y < 0))) || yy == y))
{
f = 1;
continue ;
}
}
else if(v[i] == 3)
{
xx -= mp[v[i]];
if(yy == y && ((abs(xx) >= abs(x) && ((xx >= 0 && x >= 0) || (xx < 0 && x < 0))) || xx == x))
{
f = 1;
continue ;
}
}
else
{
xx += mp[v[i]];
// if(cnt == 9)
// {
// cout << x << ' ' << y << '\n';
// cout << xx << ' ' << yy << '\n';
// }
if(yy == y && ((abs(xx) >= abs(x) && ((xx >= 0 && x >= 0) || (xx < 0 && x < 0))) || xx == x))
{
f = 1;
continue ;
}
}
}
if(f) continue ;
for(int i = 0; i < v.size(); i ++)
{
for(int j = 1; j <= mp[v[i]]; j ++)
{
cout << ump[v[i]];
}
}
cout << '\n';
// cout << cnt << '\n';
return ;
}
while(next_permutation(v.begin(),v.end()));
cout << "Impossible\n";
}
signed main()
{
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
int _ = 1;
cin >> _;
while(_ --)
{
solve();
}
// for(int i = 1; i <= _; i ++)
// {
// f = 0;
// if(i == 28) f = 1;
// else solve();
// }
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 0
Accepted
time: 25ms
memory: 3760kb
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 LLLRRRRRUU UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 25ms
memory: 3880kb
input:
11107 1 0 LLRLRURLR 1 0 LLRR 0 1 R 1 0 LLLRLRRR 1 0 RUL 0 1 UD 1 0 RLRLU 0 1 DDDUUUDU 1 0 RURRLLRLL 1 0 LRLR 1 0 ULR 0 1 R 0 1 DDUUUDR 0 1 UUDDUDDU 0 1 DDUUDU 1 0 RRLRLLRLRL 1 0 RLRRLL 1 0 LUR 1 0 U 1 0 LRRRLLLR 0 1 DRUUDDUDU 0 1 DUUDDUR 1 0 LRLRLR 0 1 UUDDDUDU 0 1 R 0 1 UDUDDU 0 1 DUUDUD 1 0 RRLRRR...
output:
ULLLLRRRR LLRR R LLLLRRRR ULR DU ULLRR DDDDUUUU ULLLLRRRR LLRR ULR R DDDUUUR DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR ULR U LLLLRRRR DDDDUUUUR DDDUUUR LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU ULLLLRRRR DDUU LLLRRR ULR ULR U ULR LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR DDDDUUUUR DDDDUUUUR LLLRRR ...
result:
ok 11107 cases