問題一覧 > 数学的知識問題

No.3009 Let's Connect with Union-Find!

レベル : / AI推定難易度 : 1800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 12
作問者 : ジュ・ビオレ・グレイス / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 11729 / 自分の提出
問題文最終更新日: 2025-01-17 22:00:39
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 455 (順位表) の他の問題:

Note

The time limit for this problem is 2,000 milliseconds. Since it is quite tight, using a fast language is recommended.

Problem Statement

You are given $M$ strings $B_1, \cdots, B_M$, each an $N$-digit binary representation. Let $b_{m, n}$ be the $n$-th digit of $B_m$. In this problem, bitwise OR and bitwise AND are denoted by $C | D, \ C \& D$, respectively.
A subset $T$ of the set $\{0,1,...,2^N-1\}$ that satisfies the following conditions is called a good set.

  • $0, B_1, \cdots, B_M, 2^N-1 \in \mathcal{T}$
  • If $C,D \in \mathcal{T}$, then $C\&D, C|D \in \mathcal{T}$
It can be proved that there exists exactly one good set with the minimum number of elements (the intersection of all good sets is again a good set); denote it by $\mathcal{T}$.
For $0 \leq C < 2^{N}$, $C$ is called divisible if, by suitably choosing $D_1, D_2 \in \mathcal{T}$ such that $C \& D_1 \neq 0, C$ and $C \& D_2 \neq 0, C$, one can achieve $C \& (D_1 | D_2) = C$ and $C \& (D_1 \& D_2) = 0$.
When $0 \leq C < 2^{N}$ is indivisible and there is no indivisible $0 \leq C' < 2^N$ other than $C$ with $C \& C' = C$, $C$ is called maximal indivisible. Output the number of maximal indivisible $C$.

Background

$\mathcal T$ forms a structure called a topology on the finite set $X = \{1, \cdots, N \}$ (Wikipedia). That is, identifying an $N$-digit binary number $b_1 \cdots b_N$ with the subset $\{ i \in X : b_i = 1 \}$ of $X$, it satisfies
$\emptyset, X \in \mathcal T,$
$U, V \in \mathcal T \Rightarrow U \cap V \in \mathcal T,$
$U, V \in \mathcal T \Rightarrow U \cup V \in \mathcal T$
.
This problem asks for the number of connected components of the topological space.

Input

$M \ N$
$b_{1, 1} b_{1, 2} \cdots b_{1, N}$
$b_{2, 1} b_{2, 2} \cdots b_{2, N}$
$\vdots$
$b_{M, 1} b_{M, 2} \cdots b_{M, N}$

$1 \leq M \leq 1024,$
$1 \leq N \leq 4096,$
$b_{i, j} \in \{ 0, 1 \} \ (1 \leq i \leq M, \ 1 \leq j \leq N).$
Note that the $B_m = b_{m, 1} b_{m, 2} \cdots b_{m, N}$ are not necessarily distinct.

Output

Print a newline at the end.

Sample

Sample 1
Input
4 4
1100
1010
1001
1100
Output
1

$\mathcal{T} = \{ 0000, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111 \}$. The only maximal indivisible value is $1111$, so the answer is 1.

Sample 2
Input
2 3
100
011
Output
2

They are the two values $100, 011$.

Sample 3
Input
1 16
0000000000000000
Output
1

It is the single value $1111111111111111$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。