codeforces-scrape

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

1520E.md (1990B)


      1 Source: https://codeforces.com/problemset/problem/1520/E
      2 
      3 E. Arranging The Sheep
      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 You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.
     22 
     23 For example, if $n=6$ and the level is described by the string "**.*..", then the following game scenario is possible:
     24 
     25 * the sheep at the $4$ position moves to the right, the state of the level: "**..*.";
     26 * the sheep at the $2$ position moves to the right, the state of the level: "*.*.*.";
     27 * the sheep at the $1$ position moves to the right, the state of the level: ".**.*.";
     28 * the sheep at the $3$ position moves to the right, the state of the level: ".*.**.";
     29 * the sheep at the $2$ position moves to the right, the state of the level: "..***.";
     30 * the sheep are lined up and the game ends.
     31 
     32 For a given level, determine the minimum number of moves you need to make to complete the level.
     33 
     34 Input
     35 
     36 The first line contains one integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
     37 
     38 The first line of each test case contains one integer $n$ ($1 \le n \le 10^6$).
     39 
     40 The second line of each test case contains a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep) — the description of the level.
     41 
     42 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.
     43 
     44 Output
     45 
     46 For each test case output the minimum number of moves you need to make to complete the level.
     47 
     48 Example
     49 
     50 Input
     51 
     52 ```
     53 5
     54 6
     55 **.*..
     56 5
     57 *****
     58 3
     59 .*.
     60 3
     61 ...
     62 10
     63 *.*...*.**
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 1
     70 0
     71 0
     72 0
     73 9
     74 ```