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;
const int oo = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
string a,b; cin >> a >> b;
for(auto& i : a) i-='0';
for(auto& i : b) i-='0';
for(int i=n-1;i>0;--i) {
a[i] ^= a[i-1];
b[i] ^= b[i-1];
}
array<int,3> dp = {0,oo,oo};
for(int i=0;i<n;++i) {
int dif = (a[i]!=b[i]);
dp = {min({dp[0]+dif,dp[1]+dif,dp[2]+!dif}), min(dp[0]+2+dif,dp[1+a[i]]+b[i]),min(dp[0]+2+!dif,dp[1+!a[i]]+b[i])};
}
cout << (*min_element(dp.begin(),dp.end())+1)/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... |