제출 #391810

#제출 시각아이디문제언어결과실행 시간메모리
391810PixelCat건물 4 (JOI20_building4)C++14
100 / 100
308 ms68852 KiB
/*                                                       
  /^--^\                                                 
  \____/                                                 
 /      \ _____  _ __  __ ____  _     ____   ____  _____ 
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|  
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
//#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int ll //__int128
#define double long double
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define For(i,a,b)    for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(1000000007)
#define INF (int)(1e12)
#define EPS (1e-7)

#ifdef NYAOWO
#define debug(...) do{\
	cerr << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
	cerr << flush;\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }
inline void USACO(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
__int128 fpow(__int128 b,__int128 p,const __int128 &mod){
	__int128 ans=1;
	while(p){
		if(p&1) ans=ans*b%mod;
		p/=2; b=b*b%mod;
	}
	return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }

#define MAXN 1000010
int a[MAXN];
int b[MAXN];
int la[MAXN];
int ha[MAXN];
int lb[MAXN];
int hb[MAXN];

int32_t main(){
	NYA();
	//nachoneko so cute >/////<
	int n; cin>>n;
	For(i,1,n*2) cin>>a[i];
	For(i,1,n*2) cin>>b[i];
	la[1]=ha[1]=0;
	lb[1]=hb[1]=1;
	For(i,2,n*2){
		la[i]=INF;
		ha[i]=-INF;
		lb[i]=INF;
		hb[i]=-INF;
		if(a[i-1]<=a[i]) { chmax(ha[i],ha[i-1]); chmin(la[i],la[i-1]); }
		if(b[i-1]<=a[i]) { chmax(ha[i],hb[i-1]); chmin(la[i],lb[i-1]); }
		if(a[i-1]<=b[i]) { chmax(hb[i],ha[i-1]); chmin(lb[i],la[i-1]); }
		if(b[i-1]<=b[i]) { chmax(hb[i],hb[i-1]); chmin(lb[i],lb[i-1]); }
		lb[i]++; hb[i]++;
	}
	int now=n;
	if((now>ha[n*2] || now<la[n*2]) && (now>hb[n*2] || now<lb[n*2])){
		cout<<"-1\n";
		return 0;
	}
	//debug(lb[n*2],hb[n*2]);
	//debug(la[n*2],ha[n*2]);
	//debug(n*2);
	string ans;
	bool ok=true;
	Forr(i,n*2,1){
		if(ok && la[i]<=now && now<=ha[i]){
			ans+='A';
			ok=(a[i-1]<=a[i]);
		}else{
			ans+='B'; now--;
			ok=(a[i-1]<=b[i]);
		}
	}
	reverse(all(ans));
	cout<<ans<<"\n"<<flush;
	//debug(now);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...