This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n; cin >> n;
ll ar[2*n], br[2*n];
string s;
for (ll i=0;i<2*n;i++) {
cin >> ar[i];
s+=".";
}
bool bisat[2*n];
memset(bisat, true, sizeof(bisat));
bool gagal = false;
vector<ll>dt;
vector<ll> lawan;
ll na=0, nb=0, mn=0;
for (ll i=0;i<2*n;i++) {
cin >> br[i];
bool ada = false;
if (ar[i]<=br[i]) {
if (ar[i]>=mn) {
s[i]='A';
na++;
dt.push_back(ar[i]);
lawan.push_back(br[i]);
mn = ar[i];
} else if (br[i]>=mn) {
bisat[i]=false;
s[i]='B';
nb++;
lawan.push_back(ar[i]);
dt.push_back(br[i]);
mn = br[i];
} else {
gagal = true;
}
} else {
if (br[i]>=mn) {
s[i]='B';
nb++;
lawan.push_back(ar[i]);
dt.push_back(br[i]);
mn = br[i];
} else if (ar[i]>=mn) {
bisat[i]=false;
s[i]='A';
na++;
lawan.push_back(br[i]);
dt.push_back(ar[i]);
mn = ar[i];
} else {
gagal = true;
}
}
}
if (gagal) {
cout << "-1" << endl;
return 0;
}
ll beda = abs(na-nb);
char car, balik;
if (na>nb) {
car = 'A';
balik = 'B';
} else if (nb>na) {
car = 'B';
balik = 'A';
} else {
cout << s << endl;
return 0;
}
dt.push_back(1e11);
for (int i=(2*n)-1;i>=0;i--) {
if (!beda) break;
if (s[i]==car) {
if (bisat[i] && lawan[i]<=dt[i+1]) {
beda-=2;
s[i]= balik;
dt[i] = lawan[i];
}
}
}
if (beda) {
cout << "-1" << endl;
return 0;
}
cout << s << endl;
return 0;
}
Compilation message (stderr)
building4.cpp: In function 'int main()':
building4.cpp:25:14: warning: unused variable 'ada' [-Wunused-variable]
25 | bool ada = false;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |