제출 #133191

#제출 시각아이디문제언어결과실행 시간메모리
133191miguelLamps (JOI19_lamps)C++14
100 / 100
113 ms4372 KiB
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 998244353;
int n, dp[3][2][2], ans=1e9;
bool a[1000002], b[1000002];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++){
        char c;
        cin>>c;
        if(c=='1') a[i]=1;
    }
    for(int i=1; i<=n; i++){
        char c;
        cin>>c;
        if(c=='1') b[i]=1;
    }
    ///cout<<a[1];
    for(int x=0; x<=2; x++){
        for(int y=0; y<2; y++){
            dp[x][y][0]=(x>0)+(y>0);
        }
    }
    //cout<<dp[2][1][0]<<endl;
//    dp[1][0]=dp[2][0]=dp[3][0]=1;
    for(int i=1; i<=n; i++){
        for(int x=0; x<=2; x++){
            for(int y=0; y<2; y++){
                dp[x][y][1]=1e9;
                int res=a[i];
                if(x>0) res=(x-1);
                res^=y;
                if(res==b[i]){
                    for(int xx=0; xx<=2; xx++){
                        for(int yy=0; yy<2; yy++) dp[x][y][1]=min(dp[x][y][1], dp[xx][yy][0]+(xx!=x && x)+(yy!=y && y));
                    }
                }
                //cout<<x<<" "<<y<<" "<<res<<endl;
            }
        }
        for(int x=0; x<=2; x++){
            for(int y=0; y<2; y++){
                dp[x][y][0]=dp[x][y][1];
                if(i==n) ans=min(ans, dp[x][y][0]);
            }
        }
    }
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...