제출 #212140

#제출 시각아이디문제언어결과실행 시간메모리
212140kshitij_sodaniBuilding 4 (JOI20_building4)C++17
100 / 100
366 ms29820 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aa[2*n];
	int bb[2*n];
	for(int i=0;i<2*n;i++){
		cin>>aa[i];
	}	
	for(int i=0;i<2*n;i++){
		cin>>bb[i];
	}
	pair<int,int> dp[2*n][2];
	dp[0][0]={1,1};
	dp[0][1]={0,0};
	for(int i=1;i<2*n;i++){
		int st=0;
		dp[i][0]={-1,-1};
		dp[i][1]={-1,-1};
		if(aa[i]>=aa[i-1]){
			if(dp[i-1][0].a!=-1){
				dp[i][0]={dp[i-1][0].a+1,dp[i-1][0].b+1};
				st=1;
			}
		}
		if(aa[i]>=bb[i-1]){
			if(dp[i-1][1].a!=-1){
				if(st==0){
					dp[i][0]={dp[i-1][1].a+1,dp[i-1][1].b+1};
					st=1;
				}
				else{
					dp[i][0].a=min(dp[i][0].a,dp[i-1][1].a+1);
					dp[i][0].b=max(dp[i][0].b,dp[i-1][1].b+1);
					st=1;
				}
			}
		}
		
		int stt=0;
		if(bb[i]>=aa[i-1]){
			if(dp[i-1][0].a!=-1){
				dp[i][1]=dp[i-1][0];

				stt=1;
			}
		}
		if(bb[i]>=bb[i-1]){
			if(dp[i-1][1].a!=-1){
				if(stt==0){
					dp[i][1]=dp[i-1][1];
				}
				else{
					dp[i][1].a=min(dp[i][1].a,dp[i-1][1].a);
					dp[i][1].b=max(dp[i][1].b,dp[i-1][1].b);
				}
			}
		}
	}
	int ans[2*n];
	int so=-1;

	if(dp[2*n-1][0].a<=n and dp[2*n-1][0].b>=n){
		so=0;
	}
	if(dp[2*n-1][1].a<=n and dp[2*n-1][1].b>=n){
		so=1;
	}

	if(so==-1){
		cout<<-1;
		return 0;
	}
	ans[2*n-1]=so;
	int co=n-(1-so);

	for(int i=2*n-2;i>=0;i--){
		int soo;
		int x=aa[i+1];
		if(ans[i+1]==1){
			x=bb[i+1];
		}
		if( dp[i][0].a<=co and dp[i][0].b>=co and aa[i]<=x and co>0){
			soo=0;
			co-=1;
		}
		else if(dp[i][1].a<=co and dp[i][1].b>=co and bb[i]<=x){
			soo=1;
		}
		ans[i]=soo;
	}
	for(int i=0;i<2*n;i++){
		if(ans[i]==0){
			cout<<"A";
		}
		else{
			cout<<"B";
		}
	}




	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

building4.cpp: In function 'int main()':
building4.cpp:100:9: warning: 'soo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans[i]=soo;
   ~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...