This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
///#include <tryhardmode>
///#include <GODMODE::ON>
using namespace std;
const int INF=1e9;
const int NMAX=1e6+5;
long long dp[NMAX][2];
int v[NMAX][2];
int n;
void get_dp(int x)
{
int i,j,k;
for(i=1;i<=n;i++)
for(j=0;j<2;j++)
dp[i][j]=-INF;
for(i=n;i>0;i--)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
if(v[i-1][j]<=v[i][k])
{
if(k==x)
dp[i][j]=max(dp[i][j],dp[i+1][k]+1);
else
dp[i][j]=max(dp[i][j],dp[i+1][k]);
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i,k;
cin>>n;
n*=2;
for(k=0;k<2;k++)
{
for(i=1;i<=n;i++)
cin>>v[i][k];
}
for(i=0;i<=1;i--)
{
get_dp(i);
if(dp[1][i]<n/2)
{
cout<<-1;
exit(0);
}
}
int curr=0,kon=n/2;
for(i=1;i<=n;i++)
{
if(v[i][1]>=curr && dp[i+1][1]>=kon)
{
cout<<"B";
curr=v[i][1];
}
else
{
cout<<"A";
kon--;
curr=v[i][0];
}
}
return 0;
}
Compilation message (stderr)
building4.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
3 | #pragma optimize GCC ("Ofast")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |