codeforces-scrape

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

1184D1.md (2915B)


      1 Source: https://codeforces.com/problemset/problem/1184/D1
      2 
      3 D1. Parallel Universes (Easy)
      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 The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.
     22 
     23 Heidi recently got her hands on a multiverse observation tool. She was able to see all $n$ universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the $k$-th universe.
     24 
     25 The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed $m$.
     26 
     27 Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.
     28 
     29 More specifically,
     30 
     31 * When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.
     32 * When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist.
     33 
     34 Heidi wants to perform a simulation of $t$ decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.
     35 
     36 Input
     37 
     38 The first line contains four integers $n$, $k$, $m$ and $t$ ($2 \le k \le n \le m \le 250$, $1 \le t \le 1000$).
     39 
     40 Each of the following $t$ lines is in one of the following formats:
     41 
     42 * "$1$ $i$" — meaning that a universe is inserted at the position $i$ ($1 \le i \le l + 1$), where $l$ denotes the current length of the multiverse.
     43 * "$0$ $i$" — meaning that the $i$-th link is broken ($1 \le i \le l - 1$), where $l$ denotes the current length of the multiverse.
     44 
     45 Output
     46 
     47 Output $t$ lines. Each line should contain $l$, the current length of the multiverse and $k$, the current position of the Doctor.
     48 
     49 It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most $m$ and when the link breaking is performed, there will be at least one universe in the multiverse.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 5 2 10 4
     57 0 1
     58 1 1
     59 0 4
     60 1 2
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 4 1
     67 5 2
     68 4 2
     69 5 3
     70 ```
     71 
     72 Note
     73 
     74 The multiverse initially consisted of 5 universes, with the Doctor being in the second.
     75 
     76 First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.
     77 
     78 Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.
     79 
     80 Then, the rightmost link was broken.
     81 
     82 Finally, a universe was added between the first and the second universe.