#P7756. [COCI 2012/2013 #3] MALCOLM
[COCI 2012/2013 #3] MALCOLM
Description
According to Malcolm’s observations, there are students in the class. If the ranks of two students differ by at most , then they are friends. If two students are friends and their name lengths are the same, then they are good friends.
Now you are given the names and ranks of these students. Find how many pairs of good friends there are in the class.
Input Format
The input has lines.
The first line contains two integers , representing the number of students in the class and the maximum rank difference allowed for being friends.
The next lines follow: the -th line contains a string, the name of the student ranked -th in the class.
Output Format
Output a single line with one integer, the number of pairs of good friends in the class.
4 2
IVA
IVO
ANA
TOM
5
6 3
CYNTHIA
LLOYD
STEVIE
KEVIN
MALCOLM
DABNEY
2
Hint
Constraints
For all testdata, , . Each string has length in and contains only uppercase English letters.
Source
This problem is from COCI 2012-2013 CONTEST 3 T3 MALCOLM. Using the original testdata settings, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号