이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |