Submission #1048819

#TimeUsernameProblemLanguageResultExecution timeMemory
10488191L1YABuilding 4 (JOI20_building4)C++17
11 / 100
29 ms11356 KiB
//1L1YA #include<bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3,unrool-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; #define Pb push_back #define F first #define S second #define endl '\n' #define sep ' ' #define all(x) x.begin(),x.end() #define al(x,n) x+1,x+n+1 #define SZ(x) ((int)x.size()) #define lc (id<<1) #define rc (lc|1) #define mid (l+r>>1) #define dokme(x) cout << x << endl, exit(0) #define sik(x) cout << x << endl;continue; #define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll oo=1e18; const int mod=1e9+7; const int inf=1e9+111; const int N=5e5+11; const int lg=23; int n,a[N][2]; pii dp[N][2]; string ans; int main(){ FastIO cin >> n; for(int j=0;j<2;j++) for(int i=1;i<=n<<1;i++) cin >> a[i][j]; dp[1][0]={0,0}; dp[1][1]={1,1}; for(int i=2;i<=n<<1;i++){ dp[i][0]=dp[i][1]={inf,-1}; for(int j=0;j<2;j++) for(int k=0;k<2;k++) if(a[i-1][j]<=a[i][k]) dp[i][k]={min(dp[i][k].F,dp[i-1][j].F+k),max(dp[i][k].S,dp[i-1][j].S+k)}; } if(!(dp[n<<1][0].F<=n && n<=dp[n<<1][0].S) && !(dp[n<<1][1].F<=n && n<=dp[n<<1][1].S)) dokme(-1); int c=n,nxt=inf; for(int i=n<<1;i;i--) if(dp[i][0].F<=c && c<=dp[i][0].S && a[i][0]<=nxt) ans+="A",nxt=a[i][0]; else ans+="B",nxt=a[i][1],c--; reverse(all(ans)); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...