| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1363357 | retarde | 건물 4 (JOI20_building4) | C++20 | 28 ms | 8196 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
int n; // ACTUAL IS 2*n
const int mxn = 5e5 + 5;
int arr[mxn][2];
int L[mxn][2], R[mxn][2];
inline void solve() {
cin >> n;
for (int i = 1; i <= 2*n; i++) cin >> arr[i][1];
for (int i = 1; i <= 2*n; i++) cin >> arr[i][0];
for (int i = 0; i <= 2*n; i++) {
L[i][0] = L[i][1] = 1e18;
R[i][0] = R[i][1] = -1e18;
}
L[1][1] = R[1][1] = 1;
L[1][0] = R[1][0] = 0;
for (int i = 2; i <= 2 * n; i++) {
for (int p = 0; p < 2; p++) {
for (int q = 0; q < 2; q++) {
if (arr[i][p] >= arr[i - 1][q]) {
L[i][p] = min(L[i][p], L[i - 1][q] + p);
R[i][p] = max(R[i][p], R[i - 1][q] + p);
}
}
}
}
auto good = [&](int i, int p, int x=n) {
return (L[i][p] <= x && x <= R[i][p]);
};
if (!good(2*n,0) && !good(2*n,1)) {
cout << "-1\n";
return;
}
int ind = 2*n;
int need = n;
int cur = 0; if (good(2*n,1)) cur = 1;
string ans = "";
while (ind>0) {
ans += "BA"[cur];
need -= cur;
if (ind==1) break;
int p = -1;
for (int pr = 0; pr < 2; pr++) {
if (arr[ind - 1][pr] <= arr[ind][cur] && good(ind - 1, pr, need)) {
p = pr;
break;
}
}
ind--;
cur = p;
}
reverse(all(ans)); cout << ans << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
