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>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const ll inf=1e9;
ll a[1000005], b[1000005], dp[2][3][2];
ll costk[2][2]={{0, 1}, {0, 0}}, costj[3][3]={{0, 1, 0}, {1, 0, 0}, {1, 1, 0}};
ll read(){char c; cin >> c; return c-'0';}
void upd(ll a, ll& b) {b=min(a, b);}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n; cin >> n;
for (ll i=1; i<=n; i++) a[i]=read();
for (ll i=1; i<=n; i++) b[i]=read();
for (ll i=0; i<2; i++)
for (ll j=0; j<3; j++)
for (ll k=0; k<2; k++)
dp[i][j][k]=inf;
dp[0][2][0]=0;
for (ll i=1; i<=n; i++)
{
ll c=i&1, p=(i^1)&1;
for (ll j=0; j<3; j++)
for (ll k=0; k<2; k++)
dp[c][j][k]=inf;
for (ll j=0; j<3; j++)
for (ll k=0; k<2; k++)
for (ll jn=0; jn<3; jn++)
for (ll kn=0; kn<2; kn++)
upd(dp[p][j][k]+costj[j][jn]+costk[k][kn], dp[c][jn][kn]);
for (ll j=0; j<3; j++)
for (ll k=0; k<2; k++)
if (((j<2?j:a[i])^k)!=b[i])
dp[c][j][k]=inf;
}
ll ans=inf;
for (ll j=0; j<3; j++)
for (ll k=0; k<2; k++)
ans=min(ans, dp[n&1][j][k]);
cout << ans;
}
# | 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... |