codeforces-scrape

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

198B.md (2907B)


      1 Source: https://codeforces.com/problemset/problem/198/B
      2 
      3 B. Jumping on Walls
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
     22 
     23 The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
     24 
     25 Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
     26 
     27 * climb one area up;
     28 * climb one area down;
     29 * jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x* + *k* of the other wall.
     30 
     31 If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
     32 
     33 The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
     34 
     35 The level is considered completed if the ninja manages to get out of the canyon.
     36 
     37 After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
     38 
     39 Input
     40 
     41 The first line contains two integers *n* and *k* (1 ≤ *n*, *k* ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly.
     42 
     43 The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
     44 
     45 The third line describes the right wall in the same format.
     46 
     47 It is guaranteed that the first area of the left wall is not dangerous.
     48 
     49 Output
     50 
     51 Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
     52 
     53 Examples
     54 
     55 Input
     56 
     57 ```
     58 7 3  
     59 ---X--X  
     60 -X--XX-
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 YES
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 6 2  
     73 --X-X-  
     74 X--XX-
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 NO
     81 ```
     82 
     83 Note
     84 
     85 In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
     86 
     87 In the second sample there's no way the ninja can get out of the canyon.