101465: [AtCoder]ABC146 F - Sugoroku

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

Takahashi is playing a board game called Sugoroku.

On the board, there are $N + 1$ squares numbered $0$ to $N$. Takahashi starts at Square $0$, and he has to stop exactly at Square $N$ to win the game.

The game uses a roulette with the $M$ numbers from $1$ to $M$. In each turn, Takahashi spins the roulette. If the number $x$ comes up when he is at Square $s$, he moves to Square $s+x$. If this makes him go beyond Square $N$, he loses the game.

Additionally, some of the squares are Game Over Squares. He also loses the game if he stops at one of those squares. You are given a string $S$ of length $N + 1$, representing which squares are Game Over Squares. For each $i$ $(0 \leq i \leq N)$, Square $i$ is a Game Over Square if $S[i] = 1$ and not if $S[i] = 0$.

Find the sequence of numbers coming up in the roulette in which Takahashi can win the game in the fewest number of turns possible. If there are multiple such sequences, find the lexicographically smallest such sequence. If Takahashi cannot win the game, print $-1$.

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq M \leq 10^5$
  • $|S| = N + 1$
  • $S$ consists of 0 and 1.
  • $S[0] =$ 0
  • $S[N] =$ 0

Input

Input is given from Standard Input in the following format:

$N$ $M$
$S$

Output

If Takahashi can win the game, print the lexicographically smallest sequence among the shortest sequences of numbers coming up in the roulette in which Takahashi can win the game, with spaces in between.

If Takahashi cannot win the game, print $-1$.


Sample Input 1

9 3
0001000100

Sample Output 1

1 3 2 3

If the numbers $1$, $3$, $2$, $3$ come up in this order, Takahashi can reach Square $9$ via Square $1$, $4$, and $6$. He cannot reach Square $9$ in three or fewer turns, and this is the lexicographically smallest sequence in which he reaches Square $9$ in four turns.


Sample Input 2

5 4
011110

Sample Output 2

-1

Takahashi cannot reach Square $5$.


Sample Input 3

6 6
0101010

Sample Output 3

6

Input

题意翻译

ABC146F 双六 【题目描述】 高桥君在玩双六棋,棋盘格由用$0$到$N$编号的共$N+1$个格子构成。每一回合,高桥君会扔一个点数$1$到$M$的骰子。如果高桥君当前在第$i$格,骰子扔出$k$点,高桥君就前进到第$i+k$格。 如果此时$i+k > N$,高桥君立刻输掉。另外,棋盘上还有若干个“GameOver格”,如果高桥停在这些格子,也立刻输掉游戏。 假设高桥君可以自由控制骰子的点数,那么他从$0$号格子出发,到达$N$号格子,最短需要多少回合?输出用最短回合到达$N$格时,每回合骰子的点数组成的序列;如果无法到达$N$号格子,输出-1。 【输入格式】 第1行,两个正整数$N,M$ 第2行,一个长为$N+1$的字符串$S$。$S_i=0$表示第$i$格是一个普通格子;$S_i=1$表示第$i$格是一个GameOver格。 【输出格式】 输出用最短回合到达$N$格时,每回合骰子的点数组成的序列,若有多种序列回合数都是最短,输出其中字典序最小的。 如果无法到达$N$号格子,输出-1。 【输入样例\#1】 ``` 9 3 0001000100 ``` 【输出样例\#1】 ``` 1 3 2 3 ``` 【样例\#1说明】 按$1,3,2,3$的顺序扔出骰子的点数,高桥君会经过第$1,4,6$格最终到达第$9$格。 无法在$3$次以内到达第$9$格。$1,3,2,3$是所有$4$次到达第$9$格的点数序列中,字典序最小的。 【数据说明】 $1 \le N \le 10^5$ $1 \le M \le 10^5$ $S$长度为$N+1$,只由字符'0'和'1'组成,保证$S_0=0$,$S_N=0$。

加入题单

上一题 下一题 算法标签: