# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364645 | parsabahrami | Lamps (JOI19_lamps) | C++17 | 78 ms | 23020 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.
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e6 + 10, MOD = 1e9 + 7;
int dp[N][3], A[N], B[N], n; char S[N];
int main() {
scanf("%d", &n);
scanf("%s", S + 1);
for (int i = 1; i <= n; i++) A[i] = S[i] - '0';
for (int i = 0; i < N; i++) dp[i][0] = dp[i][1] = dp[i][2] = MOD;
scanf("%s", S + 1);
dp[0][2] = 0;
for (int i = 1; i <= n; i++) B[i] = S[i] - '0';
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
int x = dp[i][j];
if (j != k && k != 2) x++;
int a = (j == 0 ? 0 : (j == 1 ? 1 : A[i]));
int b = (k == 0 ? 0 : (k == 1 ? 1 : A[i + 1]));
if ((!i || a == B[i]) && b != B[i + 1]) x++;
dp[i + 1][k] = min(dp[i + 1][k], x);
}
}
}
printf("%d\n", min({dp[n][0], dp[n][1], dp[n][2]}));
return 0;
}
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... |