codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1215C.md (1930B)


      1 Source: https://codeforces.com/problemset/problem/1215/C
      2 
      3 C. Swap Letters
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Monocarp has got two strings $s$ and $t$ having equal length. Both strings consist of lowercase Latin letters "a" and "b".
     22 
     23 Monocarp wants to make these two strings $s$ and $t$ equal to each other. He can do the following operation any number of times: choose an index $pos_1$ in the string $s$, choose an index $pos_2$ in the string $t$, and swap $s_{pos_1}$ with $t_{pos_2}$.
     24 
     25 You have to determine the minimum number of operations Monocarp has to perform to make $s$ and $t$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.
     26 
     27 Input
     28 
     29 The first line contains one integer $n$ $(1 \le n \le 2 \cdot 10^{5})$ — the length of $s$ and $t$.
     30 
     31 The second line contains one string $s$ consisting of $n$ characters "a" and "b".
     32 
     33 The third line contains one string $t$ consisting of $n$ characters "a" and "b".
     34 
     35 Output
     36 
     37 If it is impossible to make these strings equal, print $-1$.
     38 
     39 Otherwise, in the first line print $k$ — the minimum number of operations required to make the strings equal. In each of the next $k$ lines print two integers — the index in the string $s$ and the index in the string $t$ that should be used in the corresponding swap operation.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 4
     47 abab
     48 aabb
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 2
     55 3 3
     56 3 2
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 1
     63 a
     64 b
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 -1
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 8
     77 babbaabb
     78 abababaa
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 3
     85 2 6
     86 1 3
     87 7 8
     88 ```
     89 
     90 Note
     91 
     92 In the first example two operations are enough. For example, you can swap the third letter in $s$ with the third letter in $t$. Then $s = $ "abbb", $t = $ "aaab". Then swap the third letter in $s$ and the second letter in $t$. Then both $s$ and $t$ are equal to "abab".
     93 
     94 In the second example it's impossible to make two strings equal.