# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105081 | Just_Solve_The_Problem | Lamps (JOI19_lamps) | C++11 | 155 ms | 16636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
string a, b;
int n;
int dp[N][3];
/*
dp[pos][operation]
operation
0 = off
1 = on
2 = do not touch
*/
char make(char c, int i) {
if (i < 2) return i + '0';
return c;
}
main() {
memset(dp, 63, sizeof dp);
scanf("%d", &n);
cin >> a >> b;
a = " " + a;
b = " " + b;
dp[0][2] = 0;
int cost;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
for (int l = 0; l < 3; l++) {
cost = dp[i - 1][j];
if (j != l && l != 2)
cost++;
if ((i == 1 || make(a[i - 1], j) == b[i - 1]) && make(a[i], l) != b[i])
cost++;
dp[i][l] = min(dp[i][l], cost);
}
}
}
printf("%d\n", min(dp[n][0], min(dp[n][1], dp[n][2])));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |