QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#783979 | #6422. Evil Coordinate | surenjamts# | AC ✓ | 26ms | 3756kb | C++20 | 2.5kb | 2024-11-26 12:31:08 | 2024-11-26 12:31:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int x, y;
bool check( string s ){
int X = 0, Y = 0;
for(int i = 0; i < s.size(); i ++ ){
if( s[i] == 'U' )
Y ++;
if( s[i] == 'D' )
Y --;
if( s[i] == 'L' )
X --;
if( s[i] == 'R' )
X ++;
if( X == x && Y == y ){
return 0;
}
}
return 1;
}
signed main(){
int t;
string s;
cin >> t;
while( t -- ){
cin >> x >> y;
cin >> s;
if( x == 0 && y == 0 ){
cout << "Impossible\n";
continue;
}
int u = 0, d = 0, l = 0, r = 0;
for(int i = 0; i < s.size(); i ++ ){
if( s[i] == 'U' )
u ++;
if( s[i] == 'D' )
d ++;
if( s[i] == 'L' )
l ++;
if( s[i] == 'R' )
r ++;
}
string ans = "";
int currx = 0, curry = 0;
// zugtaj baigaa pussy pisda
if( currx <= x ){
for(int i = 1; i <= l; i ++ ){
ans += "L";
currx --;
}
}else{
for(int i = 1; i <= r; i ++ ){
ans += "R";
currx ++;
}
}
if( curry <= y ){
for(int i = 1; i <= d; i ++ ){
ans += "D";
curry --;
}
}else{
for(int i = 1; i <= u; i ++ ){
ans += "U";
curry ++;
}
}
//tulah gej baigaa zorigtoi lalar
string pisda = "";
if( currx <= x ){
for(int i = 1; i <= r; i ++ ){
pisda += "R";
}
}else{
for(int i = 1; i <= l; i ++ ){
pisda += "L";
}
}
string lalar = "";
if( curry <= y ){
for(int i = 1; i <= u; i ++ ){
lalar += "U";
}
}else{
for(int i = 1; i <= d; i ++ ){
lalar += "D";
}
}
if( check( ans + pisda + lalar ) ){
cout << ans+pisda+lalar<<"\n";
continue;
}
if( check( ans + lalar + pisda ) ){
cout << ans + lalar + pisda << "\n";
continue;
}
cout << "Impossible\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLDRRUU UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: 0
Accepted
time: 26ms
memory: 3756kb
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:
DDRRUU RUU Impossible Impossible Impossible RRDUUUUUU RRRRDDL DU Impossible LLLLRRDD LLURRDDD Impossible RDDDDLLUU LL Impossible LDRRUUU Impossible Impossible Impossible LLLLLRRRDD Impossible RL Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU ULLLD Impossible DDDLUUU UURRDD Impossi...
result:
ok 11109 cases
Test #3:
score: 0
Accepted
time: 24ms
memory: 3748kb
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:
LLLLRRRRU LLRR R LLLLRRRR LRU DU LLRRU DDDDUUUU LLLLRRRRU LLRR LRU R DDDRUUU DDDDUUUU DDDUUU LLLLLRRRRR LLLRRR LRU U LLLLRRRR DDDDRUUUU DDDRUUU LLLRRR DDDDUUUU R DDDUUU DDDUUU LLLLLRRRRR DDDDUUUU DDUU LLLLRRRRU DDUU LLLRRR LRU LRU U LRU LLLRRR LLLLLRRRRR U DDDUUU R LLLRRR DDDDRUUUU DDDDRUUUU LLLRRR ...
result:
ok 11107 cases