Submission #588708

#TimeUsernameProblemLanguageResultExecution timeMemory
588708jeroenodbLamps (JOI19_lamps)C++14
100 / 100
15 ms2800 KiB
#include "bits/stdc++.h" using namespace std; const int oo = 1e9; int main() { cin.tie(NULL)->sync_with_stdio(false); int n; cin >> n; string a,b; cin >> a >> b; for(auto& i : a) i-='0'; for(auto& i : b) i-='0'; for(int i=n-1;i>0;--i) { a[i]^=a[i-1]; b[i]^=b[i-1]; } array<int,3> dp = {0,oo,oo}; for(int i=0;i<n;++i) { int dif = (a[i]!=b[i]); dp = {min({dp[0]+dif,dp[1]+dif,dp[2]+!dif}), min(dp[0]+2+dif,dp[1+a[i]]+b[i]),min(dp[0]+2+!dif,dp[1+!a[i]]+b[i])}; } cout << (min({dp[0],dp[1],dp[2]})+1)/2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...