Submission #1092483

#TimeUsernameProblemLanguageResultExecution timeMemory
1092483LOLOLOLamps (JOI19_lamps)C++14
4 / 100
14 ms16204 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (ll)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 1e6 + 100; int f[N][3]; string a, b; char get(int x, int y) { if (y == 1) return '0'; if (y == 2) return '1'; return a[x]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("LIGHTS.inp", "r", stdin); //freopen("LIGHTS.out", "w", stdout); mem(f, 0x3f); int n; cin >> n; cin >> a >> b; f[0][0] = (a[0] != b[0]); f[0][1] = (b[0] != '0') + 1; f[0][2] = (b[0] != '1') + 1; for (int i = 1; i < n; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { char s1 = get(i - 1, j), s2 = get(i, k); int d1 = s1 != b[i - 1], d2 = s2 != b[i]; f[i][k] = min(f[i][k], f[i - 1][j] + (d1 != d2 && d2 == 1) + (k != j && k)); } } } cout << min({f[n - 1][0], f[n - 1][1], f[n - 1][2]}) << '\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...