#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <climits>
#include <random>
#include <chrono>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <ios>
#include <iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size())
#define ALL(a) begin(a), end(a)
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
int N;
string A, B;
int F[2][2][3];
void upd(int &a, int b) { if (a > b) a = b; }
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> A >> B;
FOR(i, 0, 1) FOR(j, 0, 1) FOR(k, 0, 2) F[i][j][k] = INF;
F[0][0][0] = 0;
F[0][1][0] = (A[0] != B[0]);
FOR(i, 0, N - 2) {
int id = i & 1;
FOR(j, 0, 1) FOR(k, 0, 2) F[id ^ 1][j][k] = INF;
if (B[i] == B[i + 1]) {
FOR(k, 0, 2) upd(F[id ^ 1][0][k], F[id][0][k]);
} else {
upd(F[id ^ 1][0][1], F[id][0][0] + 1);
upd(F[id ^ 1][0][2], F[id][0][1]);
upd(F[id ^ 1][0][1], F[id][0][2] + 1);
}
FOR(k, 0, 2) upd(F[id ^ 1][0][0], F[id][1][k] + 1);
if ((A[i] != B[i]) == (A[i + 1] != B[i + 1])) {
FOR(k, 0, 2) upd(F[id ^ 1][1][k], F[id][1][k]);
} else {
upd(F[id ^ 1][1][1], F[id][1][0] + 1);
upd(F[id ^ 1][1][2], F[id][1][1]);
upd(F[id ^ 1][1][1], F[id][1][2] + 1);
}
FOR(k, 0, 2) upd(F[id ^ 1][1][0], F[id][0][k] + (A[i + 1] != B[i + 1]));
}
int ans = INF;
FOR(j, 0, 1) FOR(k, 0, 2) upd(ans, F[(N - 1) ^ 1][j][k]);
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |