Submission #1368979

#TimeUsernameProblemLanguageResultExecution timeMemory
1368979ByeWorldLamps (JOI19_lamps)C++20
100 / 100
60 ms96456 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "Ofast")
#define int long long
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 1e6+10;
const int MAXA = 2e5+10;
const int SQRT = 450;
const ll INF = 2e12;
const int MOD = 1e9+7;
const int LOG = 30;
int sum(int a, int b){ 
	ll te = a+MOD+b; 
	for(; te >= MOD; ) te -= MOD;
	return (int)te;
}
void chsum(int &a, int b){ a = sum(a,b); }
int mul(int a, int b){ 
	a%=MOD; b%=MOD; ll te = 1ll*a*b%MOD; return (int)(te);
}
void chmul(int &a, int b){ a = mul(a,b); }
void chmn(auto &a, auto b){ a = min(a, b); }
void chmx(auto &a, auto b){ a = max(a, b); }

int expo(int a, int b){
	if(b==0) return 1;
	int te = expo(a, b/2); te = mul(te,te); // temporary -> te
	return (b%2 ? mul(te, a) : te);
}

int n, dp[MAXN][10], a[MAXN], b[MAXN];

int cek(int v, int mas){
	for(int i=0; i<3; i++){
		if((mas>>i) & 1){
			if(i==0) v = 0;
			if(i==1) v = 1;
			if(i==2) v ^= 1;
		}
	}
	return v;
}
signed main(){ 
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	string s; cin>>s;
	for(int i=1; i<=n; i++) a[i] = (int)(s[i-1]-'0');
	string t; cin>>t;
	for(int i=1; i<=n; i++) b[i] = (int)(t[i-1]-'0');

	for(int i=0; i<=n; i++){
		for(int ma=0; ma<8; ma++){
			dp[i][ma] = INF;
		}	
	}
	dp[0][0] = 0;
	for(int i=1; i<=n; i++){
		for(int ma=0; ma<8; ma++){
			if(cek(a[i], ma) != b[i]) continue;

			chmn(dp[i][ma], dp[i-1][ma]);
			for(int k=0; k<=2; k++){
				int oth = ma^(1<<k);
				chmn(dp[i][ma], dp[i-1][oth] + (oth < ma));
			}
		}	
	}
	int ANS = INF;
	for(int i=0; i<8; i++) chmn(ANS, dp[n][i]);
	cout << ANS << '\n';
} 
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...