// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 1000000 + 5;
int n, a[2][N];
int f[N][2][2];
void init(void) {
cin >> n;
REP(i, 2) FOR(j, 1, 2 * n) cin >> a[i][j];
}
void process(void) {
FOR(i, 0, 2 * n) FOR(j, 0, 1) {
f[i][j][0] = inf;
f[i][j][1] = -inf;
}
f[0][0][0] = f[0][0][1] = 0;
f[0][1][0] = f[0][1][1] = 0;
FOR(i, 0, 2 * n - 1) FOR(j, 0, 1) FOR(k, 0, 1) if (f[i][j][k] > -inf && f[i][j][k] < inf) {
FOR(t, 0, 1) if (a[t][i + 1] >= a[j][i]) {
minimize(f[i + 1][t][0], f[i][j][k] + (t == 0));
maximize(f[i + 1][t][1], f[i][j][k] + (t == 0));
}
}
cerr << f[2][0][1] << ' ' << f[2][0][0] << '\n';
int mn = min(f[2*n][0][0], f[2*n][1][0]);
int mx = max(f[2*n][0][1], f[2*n][1][1]);
cerr << mn << ' ' << mx << '\n';
if (mn <= n && n <= mx) {
int cur = n;
vector<char> res(2*n);
int i = 2*n;
while(i > 0) {
if (f[i][0][0] <= cur && cur <= f[i][0][1] && (i == 2*n || a[0][i] <= a[(res[i] == 'A' ? 0 : 1)][i+1]))
res[i-1] = 'A', cur--;
else res[i-1] = 'B';
i--;
}
for(auto &c : res) cout << c;
} else cout << -1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
building4.cpp: In function 'int main()':
building4.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |