luogu#P7930. [COCI 2021/2022 #1] Set
[COCI 2021/2022 #1] Set
Background
In the well-known game SET, there are cards with different numbers, shapes, colors, and so on. The player’s goal is to find an existing triplet of cards (a triple of cards, i.e., a combination of three cards) that satisfies certain rules. Marin and Josip quickly got bored with this game and made it harder.
Problem Description
In this problem, each card is defined as a length sequence consisting only of . There are cards. The cards are unordered, and it is guaranteed that the cards are pairwise different.
We define a SET as an unordered triplet of cards such that, for every position, the three sequences are either all the same or all different. Using the original wording, this is “same” or “pairwise different”. More rigorously, let the three sequences be . Then the following conditions must hold:
- .
- , we have or .
For example, satisfies the rule: positions are the same, and positions are all different.
Given these sequences, find how many essentially different SETs can be formed.
Input Format
The first line contains two positive integers .
The next lines each contain a length sequence consisting only of , representing a card.
It is guaranteed that the sequences on the cards are all different.
Output Format
Output one integer in a single line, representing the number of essentially different SETs that can be formed.
3 4
1123
1322
1221
1
2 2
11
22
0
5 3
111
222
333
123
132
2
Hint
[Sample Explanation #3]
The two SETs that can be formed are and .
[Constraints]
For all testdata, , , all are different, and .
| Subtask | Special Constraints | Score |
|---|---|---|
| No special constraints |
Notes
The total score for this problem is points.
This problem is translated from Croatian Open Competition in Informatics 2021/2022 Contest #1 T4 Set。
Translated by ChatGPT 5