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;
int n;
vector<int> A, B;
bool ok;
string ans, cur;
void recurse(int i, int last, int cntA, int cntB) {
if (ok || max(cntA, cntB) > n) return;
if (i == (n << 1)) {
ok = true;
ans = cur;
return;
}
if (A[i] >= last) {
cur.push_back('A');
recurse(i + 1, A[i], cntA + 1, cntB);
cur.pop_back();
}
if (B[i] >= last) {
cur.push_back('B');
recurse(i + 1, B[i], cntA, cntB + 1);
cur.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
A.resize(n << 1), B.resize(n << 1);
for (int i = 0; i < (n << 1); i++) cin >> A[i];
for (int i = 0; i < (n << 1); i++) cin >> B[i];
recurse(0, -1, 0, 0);
if (ok) {
cout << ans << '\n';
} else {
cout << "-1\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |