# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226764 | MKopchev | Building 4 (JOI20_building4) | C++14 | 2095 ms | 16512 KiB |
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>
using namespace std;
const int nmax=2e3+42;
bool been[2*nmax][2][nmax];
int n;
int a[2*nmax],b[2*nmax];
string current;
pair<int,int> dp[2*nmax][2];
void go(int pos,bool side,int a_taken)
{
if(side==0)current.push_back('A');
else current.push_back('B');
if(been[pos][side][a_taken])
{
current.pop_back();
return;
}
been[pos][side][a_taken]=1;
//cout<<"go "<<a_taken<<" "<<b_taken<<" "<<side<<endl;
if(a_taken==n&&pos==2*n)
{
for(int i=1;i<=2*n;i++)printf("%c",current[i]);
printf("\n");
exit(0);
}
int lst=(side==0?a[pos]:b[pos]);
int b_taken=pos-a_taken;
//use a
if(a_taken<n&&lst<=a[pos+1])go(pos+1,0,a_taken+1);
//use b
if(b_taken<n&&lst<=b[pos+1])go(pos+1,1,a_taken);
current.pop_back();
}
int main()
{
scanf("%i",&n);
for(int i=1;i<=2*n;i++)scanf("%i",&a[i]);
for(int i=1;i<=2*n;i++)scanf("%i",&b[i]);
go(0,0,0);
printf("-1\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |