codeforces-scrape

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

2004B.md (1944B)


      1 Source: https://codeforces.com/problemset/problem/2004/B
      2 
      3 B. Game with Doors
      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 There are $100$ rooms arranged in a row and $99$ doors between them; the $i$-th door connects rooms $i$ and $i+1$. Each door can be either locked or unlocked. Initially, all doors are unlocked.
     22 
     23 We say that room $x$ is reachable from room $y$ if all doors between them are unlocked.
     24 
     25 You know that:
     26 
     27 * Alice is in some room from the segment $[l, r]$;
     28 * Bob is in some room from the segment $[L, R]$;
     29 * Alice and Bob are in different rooms.
     30 
     31 However, you don't know the exact rooms they are in.
     32 
     33 You don't want Alice and Bob to be able to reach each other, so you are going to lock some doors to prevent that. What's the smallest number of doors you have to lock so that Alice and Bob cannot meet, regardless of their starting positions inside the given segments?
     34 
     35 Input
     36 
     37 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
     38 
     39 The first line of each test case contains two integers $l$ and $r$ ($1 \le l \lt r \le 100$) — the bounds of the segment of rooms where Alice is located.
     40 
     41 The second line of each test case contains two integers $L$ and $R$ ($1 \le L \lt R \le 100$) — the bounds of the segment of rooms where Bob is located.
     42 
     43 Output
     44 
     45 For each test case, print a single integer — the smallest number of doors you have to lock so that Alice and Bob cannot meet, regardless of their starting positions inside the given segments.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 4
     53 
     54 1 2
     55 
     56 3 4
     57 
     58 2 5
     59 
     60 2 5
     61 
     62 3 7
     63 
     64 6 7
     65 
     66 4 5
     67 
     68 2 8
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 1
     75 3
     76 2
     77 3
     78 ```
     79 
     80 Note
     81 
     82 In the first test case, it is sufficient to lock the door between rooms $2$ and $3$.
     83 
     84 In the second test case, the following doors have to be locked: $(2,3)$, $(3,4)$, $(4,5)$.
     85 
     86 In the third test case, the following doors have to be locked: $(5, 6)$ and $(6,7)$.