求调,样例一第一组数据只输出一个“L”QwQ
查看原帖
求调,样例一第一组数据只输出一个“L”QwQ
1127998
Hanyishuo楼主2024/10/22 22:23
#include<bits/stdc++.h>
using namespace std;

int T, n;
char c[11000000], d[110000000];
int ha = 1, ta = 1, hc = 1, hd = 1;
int h = 0, t = 0;
int qwq, cnt;
int a[1100000], aa[1100000];
bool can1 = 1, can2 = 1;

int _find(int m, int z[], int y){
	for(int i = 1; i<= 2 * n; i++){
		if(z[i] == m && i != y) return i;
	}
}

void _update(){
	ha = 1; ta = 1; hc = 1; hd = 1; h = 0; t = 0; cnt = n * 2;
	memset(c, 0, sizeof(c));
}

int main(){
	cin >> T;
	while(T--){
		_update();
		cin >> n;
		ta = 2 * n;
		for(int i = 1; i <= 2 * n; i++){
			cin >> a[i];
			aa[i] = a[i];
		}
		
		qwq = _find(a[ha], a, ha);
		h = qwq - 1;
		t = qwq + 1;
		ha++;
		c[hc] = 'L';
		while(cnt--){
			if(a[ha] == h){
		    	h--;
		    	ha++;
		    	c[++hc] = 'L';
		    	d[++hd] = 'R';
			}else
			if(a[ha] == t){
		    	t++;
		    	ha++;
		    	c[++hc] = 'L';
		    	d[++hd] = 'R';
			}else 
			if(a[ta] == t){
			    t++;
			    ta--;
			    c[++hc] = 'R';
			    d[++hd] = 'L';
		    }else 
			if(a[ta] == h){
		    	h--;
		    	ta--;
		    	c[++hc] = 'R';
		    	d[++hd] = 'L';
			}else{
				can1 = 0;
				continue;
			}
	    }
	    if(can1){
	    	for(int i = 1; i <= n; i++) cout << c[i];
	    	for(int i = n; i >= 1; i--) cout << d[i];
		    cout << '\n';
		    continue;
		}
	    else{
	    	
	    	_update();
	    	qwq = _find(aa[ta], aa, ta);
	    	h = qwq - 1;
	    	t = qwq + 1;
	    	c[hc] = 'R';
	    	while(cnt--){
	    		if(aa[ha] == h){
	    	    	h--;
	    	    	ha++;
	    	    	c[++hc] = 'L';
	    	    	d[++hd] = 'R';
		    	}else 
		    	if(aa[ha] == t){
		        	t++;
		        	ha++;
		        	c[++hc] = 'L';
		        	d[++hd] = 'R';
		    	}else 
				if(aa[ta] == t){
	    		    t++;
	    		    ta--;
	    		    c[++hc] = 'R';
	    		    d[++hd] = 'L';
	    	    }else 
		    	if(aa[ta] == h){
		        	h--;
		        	ta--;
		        	c[++hc] = 'R';
		        	d[++hd] = 'L';
		    	}else{
		    		can2 = 0;
		    		continue;
		    	}
	        }
	        if(can2 && ~can1){
	    	    for(int i = 1; i <= n; i++) cout << c[i];
	    	    for(int i = n; i >= 1; i--) cout << d[i];
		        cout << '\n';
		        continue;
		    }
	        else if(can1 == 0 && can2 == 0){
	        	cout << -1 << '\n';
	        	continue;
			}
		}
	}
		
	return 0;
}
2024/10/22 22:23
加载中...