-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path1006D. Two Strings Swaps.cpp
59 lines (47 loc) · 1.15 KB
/
1006D. Two Strings Swaps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Idea:
- Each 2 mirror indexes in `a` and `b` are solvable alone,
in other words they does not affect the other indexes.
- We can use the fact in the previous point and solve each
2 mirror indexes and add the result of them to the solution
of the problem.
*/
#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
char a[N], b[N];
int n;
int main() {
scanf("%d", &n);
scanf("%s", a + 1);
scanf("%s", b + 1);
int res = 0;
for(int i = 1, j = n; i <= j; ++i, --j) {
if(i == j) {
if(a[i] != b[i])
++res;
continue;
}
if(a[i] == b[j] && b[i] == a[j])
continue;
if(a[i] == a[j] && b[i] == b[j])
continue;
if(a[i] == b[i] && a[j] == b[j])
continue;
if(a[i] != a[j] && a[i] != b[i] && a[i] != b[j] && a[j] != b[i] && a[j] != b[j] && b[i] != b[j]) {
res += 2;
continue;
}
if(a[i] != a[j] && b[i] == b[j] && a[i] != b[i] && a[j] != b[i]) {
res += 1;
continue;
}
if(a[i] == a[j] && b[i] != b[j] && a[i] != b[i] && a[i] != b[j]) {
res += 2;
continue;
}
++res;
}
printf("%d\n", res);
return 0;
}