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 all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
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];
}
int dp=0,dp2=oo,dp3=oo;
for(int i=0;i<n;++i) {
int dif = (a[i]!=b[i]);
tie(dp,dp2,dp3) = make_tuple(min({dp+dif, dp2+dif,dp3+!dif}), min(dp+2 + !a[i],dp2+b[i]),min(dp+2 + a[i], dp3+b[i]));
if(a[i]) swap(dp2,dp3);
}
cout << (min({dp,dp3,dp2})+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... |