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;
int main() {
int n;
cin >> n;
vector<bool> on1(n + 1);
vector<bool> on2(n + 1);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
}
for (int i = 0; i < n; i++) {
bool a;
cin >> a;
on1[i] = a;
}
on2 = on1;
on2[0] = !on2[0];
on2[1] = !on2[1];
int cnt1 = 0;
int cnt2 = 1;
for (int i = 1; i < n; i++) {
if (on1[i - 1]) {
on1[i - 1] = false;
on1[i] = !on1[i];
on1[i + 1] = !on1[i + 1];
cnt1++;
}
if (on2[i - 1]) {
on2[i - 1] = false;
on2[i] = !on2[i];
on2[i + 1] = !on2[i + 1];
cnt2++;
}
}
bool allFalse1 = true;
bool allFalse2 = true;
for (int i = 0; i < n; i++) {
if (on1[i]) {
allFalse1 = false;
}
if (on2[i]) {
allFalse2 = false;
}
}
if (!allFalse1) {
cnt1 = INT_MAX;
}
if (!allFalse2) {
cnt2 = INT_MAX;
}
int ans = min(cnt1, cnt2);
if (ans == INT_MAX) {
cout << "impossible" << endl;
}
else {
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |