-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA1286.cpp
More file actions
82 lines (64 loc) · 1.11 KB
/
Copy pathA1286.cpp
File metadata and controls
82 lines (64 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
int n;
int ans = INT_MAX;
void search(vector<int> bulbs, int pos, int even, int odd)
{
if(pos == n)
{
int x = 0;
for(int i = 0; i < n-1; i++)
{
if(bulbs[i] != bulbs[i+1]) x++;
}
ans= min(x, ans);
return;
}
if(bulbs[pos] == 1 || bulbs[pos] == 0) search(bulbs, pos+1, even, odd);
if(bulbs[pos] == -1)
{
if(odd > 0)
{
bulbs[pos] = 1;
search(bulbs, pos+1, even, odd-1);
}
if(even > 0)
{
bulbs[pos] = 0;
search(bulbs, pos+1, even-1, odd);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
int odd = (n%2==1 ? (n/2 + 1) : n/2);
int even = n/2;
//cout << even << ' ' << odd << endl;
vector<int> bulbs(n);
for(int i = 0; i < n; i++)
{
int x; cin >> x;
if(x==0)
{
bulbs[i] = -1; continue;
}
if(x%2==0)
{
even--;
bulbs[i] = 0;
} else {
odd--;
bulbs[i] = 1;
}
}
//cout << even << ' ' << odd << endl;
search(bulbs, 0, even, odd);
cout << ans << '\n';
return 0;
}