codeforces-scrape

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

1558A.md (2643B)


      1 Source: https://codeforces.com/problemset/problem/1558/A
      2 
      3 A. Charmed by the Game
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Alice and Borys are playing tennis.
     22 
     23 A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.
     24 
     25 Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vice versa.
     26 
     27 Each game ends with a victory of one of the players. If a game is won by the serving player, it's said that this player holds serve. If a game is won by the receiving player, it's said that this player breaks serve.
     28 
     29 It is known that Alice won $a$ games and Borys won $b$ games during the match. It is unknown who served first and who won which games.
     30 
     31 Find all values of $k$ such that exactly $k$ breaks could happen during the match between Alice and Borys in total.
     32 
     33 Input
     34 
     35 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). Description of the test cases follows.
     36 
     37 Each of the next $t$ lines describes one test case and contains two integers $a$ and $b$ ($0 \le a, b \le 10^5$; $a + b \gt 0$) — the number of games won by Alice and Borys, respectively.
     38 
     39 It is guaranteed that the sum of $a + b$ over all test cases does not exceed $2 \cdot 10^5$.
     40 
     41 Output
     42 
     43 For each test case print two lines.
     44 
     45 In the first line, print a single integer $m$ ($1 \le m \le a + b + 1$) — the number of values of $k$ such that exactly $k$ breaks could happen during the match.
     46 
     47 In the second line, print $m$ distinct integers $k_1, k_2, \ldots, k_m$ ($0 \le k_1 \lt k_2 \lt \ldots \lt k_m \le a + b$) — the sought values of $k$ in increasing order.
     48 
     49 Example
     50 
     51 Input
     52 
     53 ```
     54 3
     55 2 1
     56 1 1
     57 0 5
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 4
     64 0 1 2 3
     65 2
     66 0 2
     67 2
     68 2 3
     69 ```
     70 
     71 Note
     72 
     73 In the first test case, any number of breaks between $0$ and $3$ could happen during the match:
     74 
     75 * Alice holds serve, Borys holds serve, Alice holds serve: $0$ breaks;
     76 * Borys holds serve, Alice holds serve, Alice breaks serve: $1$ break;
     77 * Borys breaks serve, Alice breaks serve, Alice holds serve: $2$ breaks;
     78 * Alice breaks serve, Borys breaks serve, Alice breaks serve: $3$ breaks.
     79 
     80 In the second test case, the players could either both hold serves ($0$ breaks) or both break serves ($2$ breaks).
     81 
     82 In the third test case, either $2$ or $3$ breaks could happen:
     83 
     84 * Borys holds serve, Borys breaks serve, Borys holds serve, Borys breaks serve, Borys holds serve: $2$ breaks;
     85 * Borys breaks serve, Borys holds serve, Borys breaks serve, Borys holds serve, Borys breaks serve: $3$ breaks.