이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*raghav0307 - Raghav Gupta*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int MAXN = 1e6 + 5;
int a[MAXN], b[MAXN];
int ans[MAXN];
signed main(){
fast_io();
int n; cin >> n;
for(int i = 0; i < 2*n; i++)
cin >> a[i];
for(int i = 0; i < 2*n; i++)
cin >> b[i];
memset(ans, -1, sizeof(ans));
int x = 0, y = 0;
int last = min(a[0], b[0]);
for(int i = 1; i < 2*n; i++){
if(a[i] < last and b[i] < last){
cout << "-1\n";
return 0;
}
else if(a[i] < last){
y++;
last = b[i];
ans[i] = 2;
}
else if(b[i] < last){
x++;
last = a[i];
ans[i] = 1;
}
else{
last = min(a[i], b[i]);
}
}
last = max(a[2*n-1], b[2*n-1]);
for(int i = 2*n-2; i >= 0; i--){
if(a[i] > last and b[i] > last){
cout << "-1\n";
return 0;
}
else if(a[i] > last){
y++;
last = b[i];
ans[i] = 2;
}
else if(b[i] > last){
x++;
last = a[i];
ans[i] = 1;
}
else{
last = max(a[i], b[i]);
}
}
for(int i = 0; i < 2*n; i++){
if(ans[i] == 1){
cout << "A";
}
else if(ans[i] == 2){
cout << "B";
}
else if(x < n and y < n){
if(a[i] <= b[i]){
cout << "A";
x++;
}
else{
cout << "B";
y++;
}
}
else if(x < n){
cout << "A";
x++;
}
else{
cout << "B";
y++;
}
}
cout << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |