Submission #1158539

#TimeUsernameProblemLanguageResultExecution timeMemory
1158539dostsLamps (JOI19_lamps)C++20
100 / 100
14 ms2788 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>

const int inf = 2e9,N = 4e5+1,MOD =  1e9+7;


void chmin(int& a,int b){
    a = min(a,b);
}

void solve() {
    int n;
    cin >> n;
    string a,b;
    cin >> a >> b;
    for (auto& it : a) it-='0';
    for (auto& it : b) it-='0';
    int dp[3],dp2[3];
    dp[0] = dp[1] = dp[2] = dp2[0] = dp2[1] = inf;
    dp2[2] = 0;
    auto now = [&](int p,int t) {
        if (t < 2) return t;
        if (!p) return (int)(t==1);
        return (int)a[p-1];
    };
    for (int i = 0;i<n;i++) {
        for (int j = 0;j<=2;j++) {
            if (dp2[j] == inf) continue;
            int swi = (i && (now(i,j) != b[i-1]));
            for (int jj = 0;jj<3;jj++) chmin(dp[jj],dp2[j]+(jj<2 && j!=jj)+(!swi && now(i+1,jj)!=b[i]));
        }
        for (int j = 0;j<3;j++) {
            dp2[j] = dp[j];
            dp[j] = inf;
        }
    }
    int ans = inf;
    for (int j = 0;j<3;j++) ans = min(ans,dp2[j]);
    cout << ans << '\n';
}


int32_t main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi 
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while (t --> 0) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...