# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1170811 | hainam2k9 | Building 4 (JOI20_building4) | C++20 | 1 ms | 328 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e6+5;
const string NAME = "";
int n;
pair<int,int> p[MAXN],dp[MAXN][2];
vector<char> v;
void add(pair<int,int>& a, pair<int,int> b){
if(b.fi==-1||b.se==-1) return;
if(a.fi==-1||a.se==-1) return a=b, void();
a.fi=min(a.fi,b.fi), a.se=max(a.se,b.se);
}
int check(int pos, int cnt){
if(dp[pos][0].fi<=cnt&&cnt<=dp[pos][0].se) return 0;
if(dp[pos][1].fi<=cnt&&cnt<=dp[pos][1].se) return 1;
return 2;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n;
for(int i = 1; i<=n<<1; ++i)
cin >> p[i].fi;
for(int i = 1; i<=n<<1; ++i){
cin >> p[i].se;
dp[i][0]=dp[i][1]={-1,-1};
}
dp[1][0]={0,0};
dp[1][1]={1,1};
for(int i = 2; i<=n<<1; ++i){
if(p[i].fi>=p[i-1].fi) add(dp[i][0],dp[i-1][0]);
if(p[i].fi>=p[i-1].se) add(dp[i][0],dp[i-1][1]);
if(p[i].se>=p[i-1].fi) add(dp[i][1],{dp[i-1][0].fi+1,dp[i-1][0].se+1});
if(p[i].se>=p[i-1].se) add(dp[i][1],{dp[i-1][1].fi+1,dp[i-1][1].se+1});
}
if(check(n<<1,n)==2) return cout << -1, 0;
for(int i=n<<1, cnt=n; i>0; --i){
if(check(i,cnt)==0) v.pb('A');
else v.pb('B'), --cnt;
}
reverse(v.begin(),v.end());
for(char& c : v) cout << c;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |