제출 #1093924

#제출 시각아이디문제언어결과실행 시간메모리
1093924coldbr3w건물 4 (JOI20_building4)C++17
100 / 100
216 ms69232 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<long long, long long> #define pb push_back #define F first #define S second #define all(x) (x).begin(), (x).end() const ll N = 1e6 + 100; const ll inf = 1e18; const ll mod = 1e9 + 7; const ll block = 350; ll n; ll a[N][2]; pll dp[N][2]; void to_thic_cau(){ cin >> n; for(int i = 1; i <= 2 * n;i++) cin >> a[i][0]; for(int i = 1; i <= 2 * n;i++) cin >> a[i][1]; dp[0][0] = dp[0][1] = {0, 0}; for(int i = 1; i <= 2 * n;i++){ dp[i][0] = dp[i][1] = {-1, -1}; for(int j = 0; j <= 1;j++){ if(dp[i-1][j].F != -1){ for(int k = 0; k <= 1;k++){ if(a[i-1][j] <= a[i][k]){ pll cur = dp[i-1][j]; cur.F += k, cur.S += k; if(dp[i][k].F == -1) dp[i][k] = cur; else dp[i][k].F = min(dp[i][k].F, cur.F), dp[i][k].S = max(dp[i][k].S, cur.S); } } } } } ll st = -1; for(int j = 0; j <= 1;j++){ if(dp[2 * n][j].S >= n && dp[2 * n][j].F <= n) st = j; } if(st == -1){ cout << -1 << '\n'; return; } string ans; ll cnt = 0; for(int i = 2 * n; i >= 1;i--){ ans.pb('A' + st); cnt += st; for(int j = 0; j <= 1;j++) if(a[i-1][j] <= a[i][st]){ if(dp[i-1][j].F + cnt <= n && dp[i-1][j].S + cnt >= n){ st = j; break; } } } reverse(all(ans)); cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); ll tc = 1; //cin >> tc; while(tc--) to_thic_cau(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...