# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210734 | arman_ferdous | Lamps (JOI19_lamps) | C++17 | 252 ms | 113912 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;
using ll = long long;
const int N = 1e6+10;
const int oo = 1e9;
int n, ans;
char a[N], b[N];
int dp[8][N];
int get(int x, int mask) {
if(mask & 1) x = 0;
if(mask & 2) x = 1;
if(mask & 4) x ^= 1;
return x;
}
int DP(int prev, int pos) {
if(pos < 0) return 0;
if(dp[prev][pos] != -1) return dp[prev][pos];
int &ret = dp[prev][pos]; ret = oo;
for(int i = 0; i < 7; i++)
if(get(a[pos] - '0', i) == b[pos] - '0')
ret = min(ret, __builtin_popcount(~prev & i) + DP(i, pos - 1));
return ret;
}
int main() {
scanf("%d", &n);
scanf(" %s %s", a, b);
memset(dp, -1, sizeof dp);
printf("%d\n", DP(0, n - 1));
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... |