COCI '25 Contest 1 #1 Rima

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

In Croatian class, Jakov reads a poem consisting of n lines and n/4 stanzas. Lines 1, 2, 3, and 4 make up the first stanza, lines 5, 6, 7, and 8 the second stanza, and so on. Each line in each stanza consists of exactly m words.

We say that two lines rhyme if the last k letters of their last words match. If the last word in one of the lines consists of fewer than k letters, then the lines do not rhyme.

At the stanza level, we distinguish three types of rhyme schemes:

  • AABB – lines 1 and 2 rhyme, and lines 3 and 4 rhyme
  • ABAB – lines 1 and 3 rhyme, and lines 2 and 4 rhyme
  • ABBA – lines 1 and 4 rhyme, and lines 2 and 3 rhyme

The teacher asked Jakov to determine in how many stanzas of the poem each of these three types of rhyme schemes appears. Help Jakov answer the teacher correctly and get an A in Croatian class!

Input Specification

The first line contains the natural numbers n, m and k (1 \le n \le 500 and n is divisible by 4, 1 \le m, k \le 20) from the text of the task.

The next n lines contain m words each, with each word being made up of at most 20 lowercase letters of the English alphabet.

Output Specification

In the first and only line, write three numbers: the number of stanzas in which AABB rhyme appears, the number of stanzas in which ABAB rhyme appears, and the number of stanzas in which ABBA rhyme appears.

Constraints

Subtask Points Constraints
1 15 n=4
2 15 Each word is made up of 1 character.
3 20 No additional constraints.

Sample Input 1

8 2 3
aa bb
cc bb
dd ee
ff ee
auu aaaaaahh
auu wer
asdf power
lol kldahh

Sample Output 1

0 0 1

Explanation for Sample Output 1

In the first stanza, not a single pair of lines can rhyme, because each last word has only 2 letters, and k = 3. The second stanza follows an ABBA rhyme scheme because the 1st and 4th lines rhyme (aaaaaahh and kldahh), and the 2nd and 3rd lines also rhyme (wer and power). Thus, AABB and ABAB rhymes occur 0 times, while ABBA rhyme occurs once.

Sample Input 2

8 2 2
ja programiram
mjesec listopad
ponekad chillam
voda vodopad
banana jabuka
fiziku znam
teska odluka
njam njam

Sample Output 2

0 2 0

Sample Input 3

4 4 2
pas konj zec macka
trokut teziste poluravnina tocka
nogomet tenis ragbi odbojka
sir mlijeko kulen sunka

Sample Output 3

1 1 1

Explanation for Sample Output 3

In the only stanza of this poem, the last two letters of the last word in each line are ka, so all lines rhyme with each other. It follows that all three types of rhyme schemes appear in this stanza: AABB, ABAB and ABBA.


Comments

There are no comments at the moment.