Submission #589261

#TimeUsernameProblemLanguageResultExecution timeMemory
589261SlavicGLamps (JOI19_lamps)C++17
6 / 100
9 ms6388 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() #define int long long const int inf = 1e16; const int N = 1e2 + 10; ll dp[N][2][2][2][2]; void solve() { int n; string a, b; cin >> n >> a >> b; forn(I, N) forn(A, 2) forn(B, 2) forn(C, 2) forn(D, 2) dp[I][A][B][C][D] = inf; dp[0][0][0][0][0] = 0; a = "?" + a; b = "?" + b; for(int i = 1; i <= n; ++i) { for(int prev_set_0: {0, 1}) { for(int prev_set_1: {0, 1}) { if(prev_set_0 && prev_set_1) continue; for(int prev_set_xor_before: {0, 1}) { for(int prev_set_xor_after: {0, 1}) { if(prev_set_xor_after && prev_set_xor_before) continue; for(int set_0: {0, 1}) { for(int set_1: {0, 1}) { if(set_0 && set_1) continue; for(int set_xor_before: {0, 1}) { for(int set_xor_after: {0, 1}) { if(set_xor_after && prev_set_xor_before) continue; int newmoves = 0; if(set_0 && !prev_set_0) ++newmoves; if(set_1 && !prev_set_1) ++newmoves; if(set_xor_before && !prev_set_xor_before) ++newmoves; if(set_xor_after && !prev_set_xor_after) ++newmoves; int x = (a[i] - '0'); if(set_xor_before) x ^= 1; if(set_0) x = 0; if(set_1) x = 1; if(set_xor_after) x ^= 1; if(x != b[i] - '0') continue; dp[i][set_0][set_1][set_xor_before][set_xor_after] = min(dp[i][set_0][set_1][set_xor_before][set_xor_after], dp[i - 1][prev_set_0][prev_set_1][prev_set_xor_before][prev_set_xor_after] + newmoves); } } } } } } } } } int ans = inf; for(int A: {0, 1}) for(int B: {0, 1}) for(int C: {0, 1}) for(int D: {0, 1}) ans = min(ans, dp[n][A][B][C][D]); cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 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...