Submission #487820

#TimeUsernameProblemLanguageResultExecution timeMemory
487820cfalasThe Xana coup (BOI21_xanadu)C++14
0 / 100
78 ms1036 KiB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n;
vi a, b;

int main(){
	cin>>n;
	FOR(i,n-1){
		int a, b;
		cin>>a>>b;
	}
	a.resize(n);
	b.resize(n);
	FOR(i,n){
		cin>>a[i];
		b[i] = a[i];
	}
	int ans1=0;
	bool ok1=false;
	FORi(i,1,n-1){
		if(a[i-1]==1){
			a[i-1] = 1-a[i-1];
			a[i] = 1-a[i];
			a[i+1] = 1-a[i+1];
			ans1++;
		}
	}
	if(a[n-1]+a[n-2]==0) ok1=true;

	int ans2=1;
	FOR(i,n) a[i] = b[i];
	a[0] = 1-a[0];
	a[1] = 1-a[1];
	FORi(i,1,n-1){
		if(a[i-1]==1){
			a[i-1] = 1-a[i-1];
			a[i] = 1-a[i];
			a[i+1] = 1-a[i+1];
			ans2++;
		}
	}

	if(a[n-1]+a[n-2]+a[n]!= 0 && !ok1) cout<<"impossible\n";
	else if(!ok1) cout<<ans2<<endl;
	else if(a[n-1]+a[n-2]!=0) cout<<ok1<<endl;
	else cout<<min(ans1, ans2);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...