codeforces-scrape

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

1243B1.md (1877B)


      1 Source: https://codeforces.com/problemset/problem/1243/B1
      2 
      3 B1. Character Swap (Easy Version)
      4 
      5 time limit per test
      6 
      7 1 second
      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 This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
     22 
     23 After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
     24 
     25 Ujan has two distinct strings $s$ and $t$ of length $n$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions $i$ and $j$ ($1 \le i,j \le n$, the values $i$ and $j$ can be equal or different), and swaps the characters $s_i$ and $t_j$. Can he succeed?
     26 
     27 Note that he has to perform this operation exactly once. He has to perform this operation.
     28 
     29 Input
     30 
     31 The first line contains a single integer $k$ ($1 \leq k \leq 10$), the number of test cases.
     32 
     33 For each of the test cases, the first line contains a single integer $n$ ($2 \leq n \leq 10^4$), the length of the strings $s$ and $t$.
     34 
     35 Each of the next two lines contains the strings $s$ and $t$, each having length exactly $n$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
     36 
     37 Output
     38 
     39 For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
     40 
     41 You can print each letter in any case (upper or lower).
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 5
     50 souse
     51 houhe
     52 3
     53 cat
     54 dog
     55 2
     56 aa
     57 az
     58 3
     59 abc
     60 bca
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 Yes
     67 No
     68 No
     69 No
     70 ```
     71 
     72 Note
     73 
     74 In the first test case, Ujan can swap characters $s_1$ and $t_4$, obtaining the word "house".
     75 
     76 In the second test case, it is not possible to make the strings equal using exactly one swap of $s_i$ and $t_j$.