QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571978#6422. Evil CoordinateZhi_zI#AC ✓11ms4000kbC++172.9kb2024-09-18 10:49:082024-09-18 10:49:09

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 10:49:09]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:4000kb
  • [2024-09-18 10:49:08]
  • 提交

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 ++ ;
		}
	}
	
	int p[5] = { 114514 , 1 ,2 ,3 ,4};
	
	// 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( p + 1 , p + 5 ) );
	
	if ( !judge ) {
		cout << "Impossible\n";
    	return ;
	}
	
	return ;
}
 
signed main()
{   
    IOS;
    int _ = 1;
    cin >> _;
 
    while ( _ -- ) 
        Rainbow_();
 
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

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: 11ms
memory: 4000kb

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: 3ms
memory: 3744kb

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