Submission #1181659

#TimeUsernameProblemLanguageResultExecution timeMemory
1181659rythm_of_knightLamps (JOI19_lamps)C++17
0 / 100
1098 ms12104 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++) { if (a[i] == b[i]) { dp[i] = dp[i - 1]; continue; } vector <int> cnt(3, 0); int now = 2, tog = 1, st = 2; for (int j = i; j >= 1; j--) { if (b[j] != now) cnt[b[j]]++; if (st != 2 && st != b[j]) st = 2; now = b[j]; if (a[j] == b[j]) { if (st != b[j]) { tog++; st = b[j]; } } dp[i] = min(dp[i], dp[j - 1] + min(min(cnt[0] + (cnt[1] > 0), cnt[1] + (cnt[0] > 0)), tog)); } } 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...