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;
#define int long long
const int INF = 1e18;
void r(int &a, int b){ a = min(a, b); }
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n; string a, b; cin >> n >> a >> b;
array<int, 3> dp = {0, INF, INF}, c;
for(int i=0; i<n; ++i){
c = {INF, INF, INF};
array<bool, 3> prev = {b[i-1] != a[i-1], b[i-1] == '1', b[i-1] == '0'};
array<bool, 3> curr = {b[i] != a[i], b[i] == '1', b[i] == '0'};
for(int j=0; j<3; ++j){
for(int k=0; k<3; ++k){
int cost = (k && k!=j) + (curr[k] && curr[k] != prev[j]);
r(c[k], dp[j] + cost);
}
}
swap(c, dp);
}
cout << min(dp[0], min(dp[1], dp[2]));
}
# | 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... |