Submission #535826

#TimeUsernameProblemLanguageResultExecution timeMemory
535826DJ035Building 4 (JOI20_building4)C++17
0 / 100
2 ms468 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <bits/stdc++.h> #define MEM 2222 #define sanic ios_base::sync_with_stdio(0) #define x first #define y second #define pf push_front #define pb push_back #define all(v) v.begin(), v.end() #define sz size() using namespace std; typedef long long ll; typedef pair<ll, ll> pi; const ll INF = 1e17+7; const ll MOD = 998244353; ll gcd(ll a, ll b){ if(a%b) return gcd(b, a%b); return b; } ll t,n,m; ll a[MEM],b[MEM]; ll dp[MEM][MEM][2]; void tr(ll x, ll y, ll z){ if(!x) return; if(z){ if((dp[x-1][y][0]) && (a[x-1]<=b[x])) tr(x-1, y, 0); else tr(x-1, y, 1); cout << 'B'; } else{ if((dp[x-1][y-1][0]) && (a[x-1]<=a[x])) tr(x-1, y-1, 0); else tr(x-1, y-1, 1); cout << 'A'; } } signed main(){ sanic; cin.tie(0); cin >> n; n<<=1; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=n; i++) cin >> b[i]; dp[0][0][0] = dp[0][0][1] = 1; for(int i=1; i<=n; i++){ for(int j=0; j<=i; j++){ if(j) dp[i][j][0] = ((dp[i-1][j-1][0]) && (a[i-1]<=a[i]))|((dp[i-1][j-1][1]) && (b[i-1]<=a[i])); dp[i][j][1] = ((dp[i-1][j][0]) && (a[i-1]<=b[i]))|((dp[i-1][j][1]) && (b[i-1]<=b[i])); } } if(dp[n][n/2][0]) tr(n, n/2, 0); else if(dp[n][n/2][1]) tr(n, n/2, 1); else cout << -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...