codeforces-scrape

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

1476D.md (2399B)


      1 Source: https://codeforces.com/problemset/problem/1476/D
      2 
      3 D. Journey
      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 There are $n + 1$ cities, numbered from $0$ to $n$. $n$ roads connect these cities, the $i$-th road connects cities $i - 1$ and $i$ ($i \in [1, n]$).
     22 
     23 Each road has a direction. The directions are given by a string of $n$ characters such that each character is either L or R. If the $i$-th character is L, it means that the $i$-th road initially goes from the city $i$ to the city $i - 1$; otherwise it goes from the city $i - 1$ to the city $i$.
     24 
     25 A traveler would like to visit as many cities of this country as possible. Initially, they will choose some city to start their journey from. Each day, the traveler must go from the city where they currently are to a neighboring city using one of the roads, and they can go along a road only if it is directed in the same direction they are going; i. e., if a road is directed from city $i$ to the city $i + 1$, it is possible to travel from $i$ to $i + 1$, but not from $i + 1$ to $i$. After the traveler moves to a neighboring city, all roads change their directions to the opposite ones. If the traveler cannot go from their current city to a neighboring city, their journey ends; it is also possible to end the journey whenever the traveler wants to.
     26 
     27 The goal of the traveler is to visit as many different cities as possible (they can visit a city multiple times, but only the first visit is counted). For each city $i$, calculate the maximum number of different cities the traveler can visit during exactly one journey if they start in the city $i$.
     28 
     29 Input
     30 
     31 The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
     32 
     33 Each test case consists of two lines. The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$). The second line contains the string $s$ consisting of exactly $n$ characters, each character is either L or R.
     34 
     35 It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, print $n + 1$ integers. The $i$-th integer should be equal to the maximum number of different cities the traveler can visit during one journey if this journey starts in the $i$-th city.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 2
     47 6
     48 LRRRLL
     49 3
     50 LRL
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1 3 2 3 1 3 2
     57 1 4 1 4
     58 ```