#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[3][4], G[3][4];
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, 2) FOR(j, 0, 3) F[i][j] = INF;
F[2][0] = 0;
FOR(idx, 0, N - 1) {
FOR(i, 0, 2) FOR(j, 0, 3) G[i][j] = INF;
FOR(i, 0, 2) {
upd(G[i][1], F[i][0] + 1);
if (idx > 0 && B[idx - 1] == B[idx]) {
FOR(j, 1, 3) upd(G[i][j], F[i][j]);
} else {
upd(G[i][2], F[i][1] + 1);
upd(G[i][3], F[i][2]);
upd(G[i][2], F[i][3] + 1);
}
}
bool toggle = (A[idx] != B[idx]);
FOR(j, 0, 3) {
upd(G[toggle][0], F[toggle][j]);
upd(G[toggle][0], F[!toggle][j] + 1);
upd(G[toggle][0], F[2][j] + 1);
}
FOR(i, 0, 2) FOR(j, 0, 3) F[i][j] = G[i][j];
}
int ans = INF;
FOR(i, 0, 2) FOR(j, 0, 3) upd(ans, F[i][j]);
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
3 |
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 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |