| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 12 | 4 | 2 | 50.000% |
In the attic of grandparents’ home Neringa has found a set of cards. Each card has four capital Latin letters written on it as a 2ドル \times 2$ grid. The set has $N$ cards and all of them are distinct.
Neringa noticed that some cards may be placed next to each other so that the pairs of letters on both cards adjacent to the connecting edge would be identical.
Let’s call the pairs of cards that could paired in the way described above as matching. To match a pair of cards it is allowed to move them but not allowed to rotate or flip. A card can form multiple matching pairs.
and match: ,
and match: , , , ,
and do not match.
Figure 1: Matching and not matching pairs of cards. The second pair of cards can be matched in four different ways.
Calculate the amount of matching card pairs in the card set discovered by Neringa.
The total amount of cards $N$ is given in the first row.
The remaining 2ドルN$ rows describe the cards. Each of the rows contains two capital Latin letters. One card is described by two consecutive input rows.
Output the amount of matching card pairs.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 16 | Each card has at least three |
| 2 | 20 | $N ≤ 2500$ |
| 3 | 20 | $N ≥ 26^4 - 2500$ |
| 4 | 19 | Each card has four different letters |
| 5 | 25 | No additional constraints |
3 IO OI AA AA OI IO
1
Even though the first and the third cards could be matched in four different ways, they still make only one matching pair. The second card cannot be matched with itself.
2 QW XZ AB CD
0
No matching pairs.
Olympiad > Lithuanian Olympiad in Informatics > Lithuanian Olympiad in Informatics 2018/2019 > Final Round 4번