-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1215C.cpp
More file actions
45 lines (37 loc) · 1.26 KB
/
1215C.cpp
File metadata and controls
45 lines (37 loc) · 1.26 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
void f(string &s, string &t, vpii &result, char first, char second) {
for(int i = 0, prev = -1; i < s.size(); i++) {
if(s[i] == first && t[i] == second) {
if(prev == -1) prev = i;
else {
swap(t[prev], s[i]);
result.push_back({prev, i});
prev = -1;
}
}
}
}
int main() {
int n; cin >> n;
string s, t; cin >> s >> t;
vpii result;
f(s, t, result, 'a', 'b');
f(s, t, result, 'b', 'a');
auto it1 = find_if(s.begin(), s.end(), [&, i = 0](char c)mutable{ return c != t[i++]; });
auto it2 = find_if(it1 + 1, s.end(), [&, i = it1 - s.begin() + 1](char c)mutable{ return c != t[i++]; });
if(it1 != s.end() && it2 == s.end()) {
cout << -1 << endl;
}
else {
cout << result.size() + (it1 != s.end() ? 2 : 0) << endl;
for(auto &p : result)
cout << p.first + 1 << " " << p.second + 1 << endl;
if(it1 != s.end()) {
cout << it1 - s.begin() + 1 << " " << it1 - s.begin() + 1 << endl;
cout << it2 - s.begin() + 1 << " " << it1 - s.begin() + 1 << endl;
}
}
}