Submission #105172

#TimeUsernameProblemLanguageResultExecution timeMemory
105172realityLamps (JOI19_lamps)C++17
100 / 100
397 ms35704 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define vii vector < pii > #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;} template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;} template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} const int N = 1e6 + 5; const int oo = 1e9; char A[N]; char B[N]; int dp[N][2][2][2]; int main(void) { int n; cin>>n; cin>>(A+1)>>(B+1); for (int i = 0;i <= n;++i) for (int a = 0;a < 2;++a) for (int b = 0;b < 2;++b) for (int c = 0;c < 2;++c) dp[i][a][b][c] = oo; dp[0][0][0][0] = 0; for (int i = 1;i <= n;++i) { for (int a = 0;a < 2;++a) for (int b = 0;b < 2;++b) if (!a || !b) for (int c = 0;c < 2;++c) for (int d = 0;d < 2;++d) if (!c || !d) for (int e = 0;e < 2;++e) for (int f = 0;f < 2;++f) { if (c) { if ((B[i] == '0') ^ e ^ 1) { continue; } } else if (d) { if ((B[i] == '1') ^ e ^ 1) { continue; } } else if (!c && !d) { if ((A[i] == B[i]) ^ e ^ 1) { continue; } } smin(dp[i][c][d][e],dp[i - 1][a][b][f] + (c && c != a) + (d && d != b) + (e && e != f)); } } int ans = oo; for (int a = 0;a < 2;++a) for (int b = 0;b < 2;++b) for (int c = 0;c < 2;++c) smin(ans,dp[n][a][b][c]); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...