QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571972 | #6422. Evil Coordinate | Zhi_zI# | WA | 7ms | 4044kb | C++17 | 3.1kb | 2024-09-18 10:46:52 | 2024-09-18 10:46:53 |
Judging History
answer
#include <bits/stdc++.h>
/* Orther */
#define int long long
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
using namespace std;
/* Pair */
#define x first
#define y second
/* Data type */
using ll = long long;
using ull = unsigned long long;
using PII = pair<int,int>;
using VI = vector<int>;
/* STL */
#define eb emplace_back
#define ef emplace_front
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define all1(x) x.begin()+1,x.end()
/* Random */
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define random(a,b) rng()%(b-a+1)+a
/* Contest */
const int INF = 0x3f3f3f3f ; // 1e9
const int MOD = 998244353 ;
const int N = 2e5 + 10, M = 55;
char g[20][20];
void Rainbow_()
{
int mx , my;
cin >> mx >> my;
int tmp = 0;
tmp = mx;
mx = my; my = tmp ;
string s; cin >> s;
int n = s.size();
int u = 0, d = 0, l = 0, r = 0;
for (int i = 0 ; i < n ; i ++ ) {
if (s[i] =='U') {
u ++ ;
} else if (s[i] == 'D' ) {
d ++ ;
} else if (s[i] == 'L' ) {
l ++ ;
} else if (s[i] == 'R' ) {
r ++ ;
}
}
if ( (u - d == my && r - l == mx) || (mx == 0 && my == 0) ) {
cout << "Impossible\n";
return ;
}
string p = "+1234";
// u 1 / d 2 / l 3 / r 4
string ans = "";
bool judge = false ;
do {
int nowx = 0 , nowy = 0; bool ok = true ;
for (int i = 1 ; i <= 4; i ++ ) {
//cout << nowx << ' ' << nowy << '\n';
if ( p[i] == '1' ) {
if ( nowy == my && nowx + u >= mx && mx >= nowx ) {
ok = false ;
break ;
}
} else if ( p[i] == '2' ) {
if ( nowy == my && nowx >= mx && mx >= nowx - d ) {
ok = false ;
break ;
}
} else if ( p[i] == '3' ) {
if ( nowx == mx && nowy - l <= my && my <= nowy ) {
ok = false ;
break ;
}
} else if ( p[i] == '4' ) {
if ( nowx == mx && nowy + r >= my && my >= nowy ) {
ok = false ;
break ;
}
} // 四种会达到炸弹的情况
if ( p[i] == '1' ) {
nowx += u;
} else if ( p[i] == '2' ) {
nowx -= d;
} else if ( p[i] == '3' ) {
nowy -= l;
} else if ( p[i] == '4' ) {
nowy += r;
}
}
if ( ok ) {
for (int i = 1; i <= 4; i ++ ) {
if ( p[i] == '1' ) {
for (int i = 0; i < u; i ++ ) {
ans.pb('U');
}
} else if ( p[i] == '2' ) {
for (int i = 0; i < d; i ++ ) {
ans.pb('D');
}
} else if ( p[i] == '3' ) {
for (int i = 0; i < l; i ++ ) {
ans.pb('L');
}
} else if ( p[i] == '4' ) {
for (int i = 0; i < r; i ++ ) {
ans.pb('R');
}
}
}
judge = true ;
cout << ans << '\n';
break ;
}
} while ( next_permutation( all1(p) ) );
if ( !judge ) {
cout << "Impossible\n";
return ;
}
return ;
}
signed main()
{
IOS;
int _ = 1;
cin >> _;
while ( _ -- )
Rainbow_();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
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: 7ms
memory: 4044kb
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:
wrong answer case 42, participant does not find an answer but the jury does