This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=5e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
ll n,a[N],b[N],dp[N][6];
string A,B;
ll ck(ll o,ll q){
ll qf=q/2;
if(qf==1)o=0;else if(qf==2)o=1;
return ((q&1)?1^o:o);
}
ll dif(ll fr,ll ba){
ll tmp=0;
if(fr/2!=ba/2&&fr/2!=0)++tmp;
if(fr%2!=ba%2&&fr%2!=0)++tmp;
return tmp;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>A>>B;
REP1(i,n)a[i]=A[i-1]-'0',b[i]=B[i-1]-'0';
REP(j,6)dp[0][j]=(j?INF:0);
REP1(i,n){
REP(j,6){
dp[i][j]=INF;
if(ck(a[i],j)!=b[i]){dp[i][j]=INF;continue;}
REP(k,6){
dp[i][j]=min(dp[i][j],dif(j,k)+dp[i-1][k]);
}
}
}
ll ans=INF;
REP(j,6)ans=min(ans,dp[n][j]);
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |