Submission #702637

#TimeUsernameProblemLanguageResultExecution timeMemory
702637uroskLamps (JOI19_lamps)C++14
100 / 100
45 ms42508 KiB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
#define maxn 1000005
ll n;
ll a[maxn],b[maxn];
ll dp[maxn][3];
void tc(){
    cin >> n;
    string s;
    cin >> s;
    for(ll i = 1;i<=n;i++) a[i] = s[i-1]-'0';
    cin >> s;
    for(ll i = 1;i<=n;i++) b[i] = s[i-1]-'0';
    dp[0][1] = dp[0][2] = llinf;
    for(ll i = 1;i<=n;i++){
        for(ll k = 0;k<3;k++){
            dp[i][k] = llinf;
            for(ll j = 0;j<3;j++){
                ll x;
                if(k==0) x = a[i]^(dp[i-1][j]&1);
                else x = (k-1)^(dp[i-1][j]&1);
                dp[i][k] = min(dp[i][k],dp[i-1][j]+(k!=0&&k!=j)*2+(b[i]!=x));
            }
        }
    }
    ll ans = llinf;
    for(ll i = 0;i<3;i++){
        ans = min(ans,dp[n][i]+(dp[n][i]&1));
    }
    ans/=2;
    cout<<ans<<endl;
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
/**
8
11011100
01101001

13
1010010010100
0000111001011

18
001100010010000110
110110001000100101
**/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...