QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506373 | #6422. Evil Coordinate | xixu | WA | 26ms | 4012kb | C++17 | 2.7kb | 2024-08-05 16:59:24 | 2024-08-05 16:59:25 |
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;
if(f)
{
cout << x << ' ' << y << '\n';
cout << s << "\n";
return ;
}
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 ;
}
do
{
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(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';
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
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: 26ms
memory: 4012kb
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 LLLUURRRRR UDLLL Impossible UUUDDDL UUDDRR Impossi...
result:
wrong answer case 28, participant's output goes through forbidden coordinate