codeforces-scrape

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

1147A.md (2812B)


      1 Source: https://codeforces.com/problemset/problem/1147/A
      2 
      3 A. Hide and Seek
      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 Alice and Bob are playing a game on a line with $n$ cells. There are $n$ cells labeled from $1$ through $n$. For each $i$ from $1$ to $n-1$, cells $i$ and $i+1$ are adjacent.
     22 
     23 Alice initially has a token on some cell on the line, and Bob tries to guess where it is.
     24 
     25 Bob guesses a sequence of line cell numbers $x_1, x_2, \ldots, x_k$ in order. In the $i$-th question, Bob asks Alice if her token is currently on cell $x_i$. That is, Alice can answer either "YES" or "NO" to each Bob's question.
     26 
     27 At most one time in this process, before or after answering a question, Alice is allowed to move her token from her current cell to some adjacent cell. Alice acted in such a way that she was able to answer "NO" to all of Bob's questions.
     28 
     29 Note that Alice can even move her token before answering the first question or after answering the last question. Alice can also choose to not move at all.
     30 
     31 You are given $n$ and Bob's questions $x_1, \ldots, x_k$. You would like to count the number of scenarios that let Alice answer "NO" to all of Bob's questions.
     32 
     33 Let $(a,b)$ denote a scenario where Alice starts at cell $a$ and ends at cell $b$. Two scenarios $(a_i, b_i)$ and $(a_j, b_j)$ are different if $a_i \neq a_j$ or $b_i \neq b_j$.
     34 
     35 Input
     36 
     37 The first line contains two integers $n$ and $k$ ($1 \leq n,k \leq 10^5$) — the number of cells and the number of questions Bob asked.
     38 
     39 The second line contains $k$ integers $x_1, x_2, \ldots, x_k$ ($1 \leq x_i \leq n$) — Bob's questions.
     40 
     41 Output
     42 
     43 Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 5 3
     51 5 1 4
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 9
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 4 8
     64 1 2 3 4 4 3 2 1
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 0
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 100000 1
     77 42
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 299997
     84 ```
     85 
     86 Note
     87 
     88 The notation $(i,j)$ denotes a scenario where Alice starts at cell $i$ and ends at cell $j$.
     89 
     90 In the first example, the valid scenarios are $(1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5)$. For example, $(3,4)$ is valid since Alice can start at cell $3$, stay there for the first three questions, then move to cell $4$ after the last question.
     91 
     92 $(4,5)$ is valid since Alice can start at cell $4$, stay there for the first question, the move to cell $5$ for the next two questions. Note that $(4,5)$ is only counted once, even though there are different questions that Alice can choose to do the move, but remember, we only count each pair of starting and ending positions once.
     93 
     94 In the second example, Alice has no valid scenarios.
     95 
     96 In the last example, all $(i,j)$ where $|i-j| \leq 1$ except for $(42, 42)$ are valid scenarios.