Submission #1150991

#TimeUsernameProblemLanguageResultExecution timeMemory
1150991weakweakweakLamps (JOI19_lamps)C++20
0 / 100
5 ms4500 KiB
#include <bits/stdc++.h> using namespace std; int n; string a, b; int dp[2100][2][2] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b; for (char &c : a) c -= '0'; for (char &c : b) c -= '0'; a = "$"+a, b = "$"+b; memset(dp, 63, sizeof(dp)); dp[0][0][0] = 0; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { int z = min(dp[i-1][1][0], dp[i-1][0][0]); z = min(z, min(dp[i-1][1][1], dp[i-1][0][1])); dp[i][0][0] = min(dp[i][0][0], z); } else { int z = min(dp[i-1][1][0], dp[i-1][0][0]); z = min(z, min(dp[i-1][1][1], dp[i-1][0][1])); dp[i][0][0] = min(dp[i][0][0], z+1); } if (b[i] == 0) { for (int j = i; j <= n and b[j] == 0; j++) dp[j][1][0] = min(dp[j][1][0], min(dp[i-1][0][0], dp[i-1][1][0]) + 1 ); for (int j = i; j <= n and b[j] == 0; j++) dp[j][1][1] = min(dp[j][1][1], min(dp[i-1][0][1], dp[i-1][1][1]) + 1 ); } if (b[i] == 1) { for (int j = i; j <= n and b[j] == 1; j++) dp[j][1][0] = min(dp[j][1][0], min(dp[i-1][0][0], dp[i-1][1][0]) + 1 ); for (int j = i; j <= n and b[j] == 1; j++) dp[j][1][1] = min(dp[j][1][1], min(dp[i-1][0][1], dp[i-1][1][1]) + 1 ); } if (a[i] != b[i]) { for (int j = i; j <= n and b[j] != a[j]; j++) dp[j][1][1] = min(dp[j][1][1], min(dp[i-1][1][1], dp[i-1][1][0]+1)); for (int j = i; j <= n and b[j] != a[j]; j++) dp[j][1][1] = min(dp[j][1][1], dp[i-1][0][0]+1); } } int ans = INT_MAX; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) ans = min(ans, dp[n][i][j]); cout << ans << '\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...