#ABC146F. Sugoroku

Sugoroku

题目描述

Takahashi is playing a board game called Sugoroku.

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

The game uses a roulette with the MM numbers from 11 to MM. In each turn, Takahashi spins the roulette. If the number xx comes up when he is at Square ss, he moves to Square s+xs+x. If this makes him go beyond Square NN, 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 SS of length N+1N + 1, representing which squares are Game Over Squares. For each ii (0iN)(0 \leq i \leq N), Square ii is a Game Over Square if S[i]=1S[i] = 1 and not if S[i]=0S[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-1.

高桥正在玩一款名为 "Sugoroku "的棋盘游戏。

棋盘上有 N+1N + 1 个方格,编号为 00NN 。高桥从第 00 个方格开始下棋,他必须正好停在第 NN 个方格上才能获胜。

游戏使用的轮盘上有从 11MMMM 个数字。每一轮,高桥都会转动轮盘。如果数字 xx 出现在他所在的方格 ss ,他就会移动到方格 s+xs+x 。如果这使得他移动到了 NN 方格之外,他就输掉了游戏。

此外,有些方格是游戏结束方格。如果他停在其中一个方格,他也会输掉游戏。您会得到一个长度为 N+1N + 1 的字符串 SS ,表示哪些方格是游戏结束方格。对于每个 ii (0iN)(0 \leq i \leq N) 中,如果有 S[i]=1S[i] = 1ii 是游戏结束方格,如果有 S[i]=0S[i] = 0 则不是。

找出轮盘中出现的数字序列,其中高桥可以在尽可能少的回合数内赢得游戏。如果有多个这样的序列,请找出词典上最小的序列。如果高桥不能赢得游戏,则打印 1-1

输入格式

输入内容按以下格式标准输入:

NN MM
SS

输出格式

如果高桥能赢得游戏,请打印轮盘中出现的高桥能赢得游戏的最短数字序列中按词序排列的最小序列,中间留空格。

如果高桥不能赢得游戏,则打印 1-1

样例 #1

样例输入 #1

9 3
0001000100

样例输出 #1

1 3 2 3

样例 #2

样例输入 #2

5 4
011110

样例输出 #2

-1

样例 #3

样例输入 #3

6 6
0101010

样例输出 #3

6

说明

数据规模与约定

  • 1N1051 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • S=N+1|S| = N + 1
  • SS01 组成。
  • S[0]=S[0] = 0
  • S[N]=S[N] = 0

样例 11 解释

如果数字 11332233 按照这个顺序出现,高桥可以通过方格 114466 到达方格 99 。他无法在三个或更少的回合内到达方格 99 ,而这是他在四个回合内到达方格 99 的词典最小序列。

样例 22 解释

高桥无法到达方格 55 .