QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#16537. Ninelie

Statistics

题目背景

沿着单侧无尽响彻的旋律 流经眼前的街道 伴随着落幕的爱 渐行渐远

那无法传达的理想构图日渐扭曲沉寂的抵抗在此刻觉醒 冲动也在此刻姗姗来迟

支离破碎的哭喊和美梦 理想只剩下装饰的门面

哪怕城市乐于被喧嚣嘈杂所淹没

我也会继续高歌舍弃那掌控我的一切

所以只愿那静谧 再度响彻

无需畏惧 黎明已然降临

题目描述

给定一个长为 $n$ 的 $01$ 序列 $a_1, \ldots, a_n$ 以及一个正整数 $r$。

你可以对序列 $a$ 进行操作。每次操作需选定一个下标 $p$,满足 $p$ 为 $1$ 或 $n$ 或 $a_{p-1}\neq a_{p+1}$,然后将 $a_p$ 翻转(即将 $0$ 变为 $1$,将 $1$ 变为 $0$)。

请你在 $r$ 次操作内将序列 $a$ 变成全 $0$ 或全 $1$。你不需要最小化操作次数。如果无法完成,你需要报告无解。

数据保证 $\boldsymbol{r = 2 \times 10^6}$ 或 $\boldsymbol{10^6}$,具体细节请参见【数据范围】一节。

输入格式

第一行两个正整数 $n,r$。

第二行 $n$ 个整数 $a_1, \ldots, a_n$。

输出格式

若无法在 $r$ 次操作内将序列 $a$ 变成全 $0$ 或全 $1$,则输出一行一个整数 $-1$。

若存在一种构造方案,则输出两行:

  • 第一行包含一个非负整数 $m$,表示你的操作次数;你需要保证 $m\le r$,你不需要最小化 $\boldsymbol m$
  • 第二行包含 $m$ 个正整数,依次表示每次操作的下标 $p$。

样例 1 输入

4 1000000
0 0 1 0

样例 1 输出

3
2 4 1

样例 1 解释

每次操作后的序列 $a$ 分别为:

  • $[0,1,1,0]$;
  • $[0,1,1,1]$;
  • $[1,1,1,1]$。

此时序列 $a$ 中的全部元素均相同。

样例 2 输入

5 1000000
1 1 1 1 1

样例 2 输入

0

样例 3 输入

10 1000000
0 1 0 0 1 1 0 0 1 0

样例 3 输入

18
1 2 10 1 9 4 10 4 7 4 7 3 7 8 9 2 10 1

数据范围

对于所有测试数据,$2\le n\le 2\times 10^3$,$a_i\in\{0,1\}$,$r = 2 \times 10^6$ 或 $10^6$。

本题采用捆绑测试。

  • Subtask 1(20 points):$n\le 10$,$r=2\times 10^6$。
  • Subtask 2(30 points):$r=2\times 10^6$。
  • Subtask 3(50 points):$r=10^6$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.