Submission #1181645

#TimeUsernameProblemLanguageResultExecution timeMemory
1181645rythm_of_knightLamps (JOI19_lamps)C++17
0 / 100
1094 ms12100 KiB
#include <bits/stdc++.h> #define ar array #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { char c; cin >> c; a[i] = c - '0'; } for (int i = 1; i <= n; i++) { char c; cin >> c; b[i] = c - '0'; } vector <int> dp(n + 1, 1e9); dp[0] = 0; for (int i = 1; i <= n; i++) { vector <int> cnt(3, 1), c(3); int now = 2, nw = 2, eq = 0; for (int j = i; j >= 1; j--) { if (b[j] != now) cnt[b[j]]++; now = b[j]; if (a[j] == b[j]) { if (b[j] != nw) c[b[j]]++; nw = b[j]; } else { eq = 1e9; nw = 2; } dp[i] = min(dp[i], dp[j - 1] + min(min(cnt[0], cnt[1]), min(eq, c[0] + c[1] + 1))); } } cout << dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...