Submission #1151093

#TimeUsernameProblemLanguageResultExecution timeMemory
1151093LCJLYLamps (JOI19_lamps)C++20
100 / 100
102 ms127840 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<int,int>pii; typedef pair<pii,int>pi2; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); int n; string a,b; int memo[1000005][3][2]; int dp(int index, int cur, int toggle){ if(index==n){ return (cur>0)+(toggle>0); } if(memo[index][cur][toggle]!=-1) return memo[index][cur][toggle]; int ans=1e15; //toggle set if(b[index]=='1'){ ans=min(ans,dp(index+1,1,1)+(cur==2)); } else{ ans=min(ans,dp(index+1,2,1)+(cur==1)); } //toggle no set if(a[index]!=b[index]){ ans=min(ans,dp(index+1,0,1)+(cur>0)); } //no toggle set if(b[index]=='1'){ ans=min(ans,dp(index+1,2,0)+(toggle>0)+(cur==1)); } else{ ans=min(ans,dp(index+1,1,0)+(toggle>0)+(cur==2)); } //toggle no set if(a[index]==b[index]){ ans=min(ans,dp(index+1,0,0)+(cur>0)+(toggle>0)); } //cout << index << " " << cur << " " << toggle << " " << ans << "\n"; return memo[index][cur][toggle]=ans; } void solve(){ cin >> n >> a >> b; memset(memo,-1,sizeof(memo)); cout << dp(0,0,0); } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("in.txt","r",stdin); //freopen("in.txt","w",stdout); int t=1; //cin >> t; while(t--){ 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...