QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#16580. 矩阵

统计

小马宝莉的一员小马丫丫的是一个爱好矩阵的小马,他曾经尝试过将矩阵与许许多多 OI 的其他知识点结合,而今天他想要将矩阵与 $\mathbb{F}_2$ 结合。

小马丫丫找到了一个 $n \times n$ 的 $01$ 矩阵 $L$,初始时 $L$ 的所有位置都是 $0$。

小马丫丫想要对它进行一些操作。每次操作会选取一个数 $p \in [1,n]$,然后把矩阵 $L$ 的第 $p$ 行和第 $p$ 列的数分别翻转($0$ 变 $1$,$1$ 变 $0$)。注意 $L_{p,p}$ 会被翻转两遍,所以 $L_{p,p}$ 的值不会改变。

小马丫丫对某些位置有一定期望。具体来说,他会给定一个 $n \times n$ 的 $01$ 矩阵 $A$,如果位置 $(i,j)$ 满足 $A_{i,j}=1$,说明小马丫丫希望 $L_{i,j}=0$。否则说明他对 $L_{i,j}$ 没有需求。

小马丫丫想通过若干次操作使得 $L$ 满足他的所有需求,可惜他的矩阵技巧不够高超。于是他找到了你,希望你能满足他的所有需求。

为了展现你高深的矩阵技巧,他还希望你给出一个操作步数最小的方案,并且在操作步数最小的前提下,他还希望你给的操作序列字典序最小。

字典序的定义:对于两个长度为 $k$ 的操作序列 $a, b$,字典序 $a< b$ 当且仅当 $\exists \ i\in[1,k]$,满足 $a_i < b_i$ 且 $\forall j < i, a_j = b_j$。

输入格式

输入共 $n+1$ 行。

第 $1$ 行一个正整数 $n$。

第 $2\sim n+1$ 行,每行一个长度为 $n$ 的 $01$ 字符串。第 $i+1$ 行第 $j$ 个位置的字符描述 $A_{i,j}$。

输出格式

如果无论怎么操作都无法使 $L$ 满足小马丫丫的要求,输出 $-1$。

否则,输出两行:

第 $1$ 行一个整数 $k$ 表示最小的操作次数。

第 $2$ 行一个长度为 $k$ 的序列 $p_i$,相邻两个数之间用一个空格隔开,表示你的构造方案。

你需要保证在 $k$ 最小的前提下 $p$ 序列的字典序最小。

样例数据

样例 1 输入

4
0101
1010
0101
1010

样例 1 输出

2
1 3

样例 2 输入

6
011001
100011
100110
001000
011000
110000

样例 2 输出

-1

样例 3 输入

7
0110000
0000000
1000100
0100010
0000010
0001000
1000000

样例 3 输出

3
1 4 5

子任务

Subtask 1 (10pts): 保证 $n \le 4$。

Subtask 2 (20pts): 保证 $n \le 10$。

Subtask 2 (20pts): 保证 $n \le 500$。

Subtask 3 (50pts): 无特殊限制。

对于 $100\%$ 的数据,$n \le 5000$。

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.