#P9868. [NOIP2023] 词典

[NOIP2023] 词典

Problem Description

Xiao S has nn pairwise distinct words w1,w2,,wnw_1, w_2, \cdots, w_n in the dictionary, each with length mm. Each word is a string consisting of lowercase letters.

Xiao S may perform the following operation any number of times (possibly zero times): choose any word in the dictionary and swap any two characters in it.

For each 1in1 \le i \le n, Xiao S wants to know whether it is possible, through the operations above, to obtain nn new words w1,w2,,wnw'_1, w'_2, \cdots, w'_n such that for every jij \ne i, wiw'_i is lexicographically smaller than wjw'_j. For the case n=1n = 1, we agree that the property above naturally holds.

For two strings of the same length s=s1s2sLs = s_1 s_2 \cdots s_L and t=t1t2tLt = t_1 t_2 \cdots t_L, we say that ss is lexicographically smaller than tt if and only if the following holds: there exists a position ii such that ss and tt are identical before the ii-th character, and si<tis_i < t_i, i.e., the lowercase letter sis_i comes before tit_i in alphabetical order.

Input Format

The first line contains two positive integers nn and mm, representing the number of words and the length of each word.

The next nn lines each contain a lowercase string wiw_i of length mm, representing a word.

Output Format

Output one line containing a 01 string aa of length nn. For 1in1 \le i \le n, if the property described in the statement holds, then ai=a_i = 1; otherwise, ai=a_i = 0.

4 7
abandon
bananaa
baannaa
notnotn

1110

Hint

[Sample Explanation #1]

  • Without any operation, the first word is lexicographically smallest, so the first character of the output is 1.
  • Swap the first two characters of bananaa, and swap the third and sixth characters of abandon, obtaining abondan, abnanaa, baannaa, notnotn. Now the second word is lexicographically smallest, so the second character of the output is 1.
  • Swap the first and last characters of baannaa to get aaannab, leaving the other strings unchanged. Now the third word is lexicographically smallest, so the third character of the output is 1.
  • No matter how you operate, the fourth word will not be smaller than the second word, so the fourth character of the output is 0.

[Sample Explanation #2]

This sample satisfies the limits of test point 44.

[Sample Explanation #3]

This sample satisfies the limits of test point 77.

[Sample Explanation #4]

This sample satisfies the limits of test point 1010.

[Constraints]

For all testdata, it is guaranteed that: 1n30001 \le n \le 3000, 1m30001 \le m \le 3000, each wiw_i is a lowercase string of length mm, and all words are pairwise distinct.

Test Point ID nn \leq mm \leq
11 11
242 \sim 4 2626
575 \sim 7 1515 22
88 300300
99 10310^3
1010 30003000

Translated by ChatGPT 5