# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1259430 | mingga | Lamps (JOI19_lamps) | C++20 | 31 ms | 26896 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e6 + 7;
int n, f[N][2][3];
string s;
bool a[N], b[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
cin >> s;
for(int i = 1; i <= n; i++) a[i] = (s[i - 1] - 48);
cin >> s;
for(int i = 1; i <= n; i++) b[i] = (s[i - 1] - 48);
memset(f, 0x3f, sizeof f);
f[0][0][0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < 3; j++) {
for(int k = 0; k < 2; k++) {
int cur = a[i];
if(j == 1) cur = 0;
if(j == 2) cur = 1;
cur ^= k;
if(cur != b[i]) continue;
for(int tj = 0; tj < 3; tj++) {
for(int tk = 0; tk < 2; tk++) {
f[i][j][k] = min(f[i][j][k], f[i - 1][tj][tk] + (j and j != tj) + (k and !tk));
}
}
}
}
}
int ans = inf;
for(int j = 0; j < 3; j++) {
for(int k = 0; k < 2; k++) {
ans = min(ans, f[n][j][k]);
}
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |