Canadian Computing Competition: 2022 Stage 1, Junior #4, Senior #2
A class has been divided into groups of three. This division into groups might violate two types of constraints: some students must work together in the same group, and some students must work in separate groups.
Your job is to determine how many of the constraints are violated.
Input Specification
The first line will contain an integer
The next line will contain an integer
Among these
The next line will contain an integer
Each name will consist of between
The following table shows how the available
Marks Awarded | Number of Groups | Number of Constraints |
---|---|---|
Output Specification
Output an integer between
Sample Input 1
1
ELODIE CHI
0
2
DWAYNE BEN ANJALI
CHI FRANCOIS ELODIE
Output for Sample Input 1
0
Explanation of Output for Sample Input 1
There is only one constraint and it is not violated: ELODIE
and CHI
are in the same group.
Sample Input 2
3
A B
G L
J K
2
D F
D G
4
A C G
B D F
E H I
J K L
Output for Sample Input 2
3
Explanation of Output for Sample Input 2
The first constraint is that A
and B
must be in the same group. This is violated.
The second constraint is that G
and L
must be in the same group. This is violated.
The third constraint is that J
and K
must be in the same group. This is not violated.
The fourth constraint is that D
and F
must not be in the same group. This is violated.
The fifth constraint is that D
and G
must not be in the same group. This is not violated.
Of the five constraints, three are violated.
Comments
Bro the TLE
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
Just because it passes the sample cases does not mean it will pass the problem :)
Also you have TLE so maybe try different data structure.
are vectors/linked lists recommended? i got TLE(>4.000 seconds) for the first test case in batch 4, and all cases before that were at most 0.004 seconds. my answer is currently built on vectors
The part of your code where you determine if constraints are violated runs in
time, which is too slow given that 
. Try thinking of a better way to accomplish this without looping through all the constraints for each group.
Also, try the following case:
The answer should be 0.
i think i genuinely ended up opting for the worst approach lol thanks for the tip tho, along w the new test case