Submission #588700

#TimeUsernameProblemLanguageResultExecution timeMemory
588700jeroenodbLamps (JOI19_lamps)C++14
4 / 100
51 ms4160 KiB
#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1e5+1, oo = 1e9; int main() { 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]; } int dp=0,dp2=oo,dp3=oo; for(int i=0;i<n;++i) { int dif = (a[i]!=b[i]); tie(dp,dp2,dp3) = make_tuple(min({dp+dif,dp2+b[i],dp3+!b[i]}), min(dp+2+dif,(a[i]?dp3:dp2)+b[i]),min(dp+2+!dif,(a[i]?dp2:dp3)+b[i]) ); } cout << (min({dp,dp2,dp3})+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...