# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1013941 | vjudge1 | Lamps (JOI19_lamps) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,fma,popcnt,popclz")
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, dp[1000005][3][2];
string a, b;
inline void upd(int& a, int b) {a=min(a, b);}
void solve() {
cin >> n >> a >> b;
for (char &i:a) i-='0';
for (char &i:b) i-='0';
a = ' ' + a, b = ' ' + b;
memset(dp, 0x3f, sizeof(dp));
int inf = dp[0][2][0]; dp[0][2][0]=0;
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 2; k++)
for (int j1 = 0; j1 < 3; j1++)
for (int k1 = 0; k1 < 2; k1++)
if (k1^(j1<2?j1:a[i+1])==b[i+1])
upd(dp[i+1][j1][k1], k1^(j1<2?j1:a[i+1])==b[i+1] ? dp[i][j][k] + (j1<2 && j!=j1) + (k1==1 && k!=k1) : inf);
int res=inf;
for (int i=0; i<3; i++)
for (int j=0; j<2; j++)
upd(res, dp[n][i][j]);
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}