#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
n*=2;
int a[n], b[n];
int ac = 0, bc = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
}for(int j = 0; j < n; j++){
cin >> b[j];
}string s = "";
int prev = min(a[0], b[0]);
bool ok = true;
if(prev == a[0]){
ac++;
s += "A";
}else {
s += "B";
bc++;
}
for(int i = 1; i < n-1; i++){
if(min(a[i], b[i]) >= prev && max(a[i], b[i]) <= min(a[i+1], b[i+1])){
prev = min(a[i], b[i]);
s += "C";
}else {
if(min(a[i], b[i]) >= prev){
if(min(a[i], b[i]) == a[i]){
s += "A";
prev = a[i];
ac++;
}else {
s += "B";
bc++;
prev = b[i];
}
}else {
if(max(a[i], b[i]) == a[i]){
s += "A";
ac++;
prev = a[i];
}else {
s += "B";
bc++;
prev = b[i];
}
}
}
}
if(prev <= min(a[n-1], b[n-1])){
s += "C";
}else {
if(max(a[n-1], b[n-1]) == a[n-1]){
ac++;
s += "A";
}else {
bc++;
s += "B";
}
}
if(ac <= n/2 && bc <= n/2){
string ss = "";
for(auto i: s){
if(i == 'C'){
if(ac < n/2){
ss += "A";
ac++;
}else {
ss += "B";
}
}else {
ss += i;
}
}cout << ss;
}else {
cout << -1;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |