UCL Editorial

PROBLEM LINK:

Practice
Contest

Author: Erfan alimohammadi
Tester & Editorialist: Hussain Kara Fallah

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Given the results of group stage matches in a champions league for one group. You need to determine the team on top of the group’s table and the runner up. The group consists of 4 teams. Hence, 6 matches are held (between each pair).

In a single match, the team with more goals wins. When a team wins it gets 3 points, for a draw it gets 1 point and for losing it gets 0. Teams are sorted in descending order according to points, and in case of a tie according to goal difference (number of goals the team scored - the number of goals it conceded). It’s guaranteed that the group’s top team and the runner up are both unique.

EXPLANATION:

This a straight forward implementation problem.The best tool to solve it with is map (in C++) or any equivalent structure in any other programming language. If you don’t know it, you must learn about it. In simple words, it creates a structure like a dictionary, which a field containing information about some word. Both the word and the info can be of any standard type or even (custom object but with some conditions I will not be mentioning).

So here we will have maps like:

map < string , int > points , goals;

The first map tells the number of points associated with each club name. For example points[“barcelona”] indicates the number of points associated with the string “barcelona”.

After we read the input, we fix the number of points associated with each team and the number of goals as well. After this, we can sort the 4 teams with any sorting algorithm (or even simple if cases) using the information in the maps.

In my C++ code, I wrote a custom comparator, that compares between two strings according to the data in the maps and then used it along with std::sort function. Please refer to my code for details.

AUTHOR’S AND TESTER’S SOLUTIONS:

AUTHOR’s solution

TESTER’s solution

2 Likes

Hi, I have attempted the code, and it passes the usecase examples given. But the solution is not accepted. It would be helpful for debugging if you could let me the scenario where my solution is failing.
https://www.codechef.com/viewsolution/25331715

1 Like

any site or book where to learn about maps in java? or if anyone could help…
will be a great help :slight_smile:

https://www.codechef.com/viewsolution/25598901
here is my code please help me with the test cases, i don’t know at which point it is going wrong.

A python solution using pandas:
https://www.codechef.com/viewsolution/25935912

Seem to be having the same issue as some other people. The test case is passing but not the final submit
https://www.codechef.com/viewsolution/26197398

https://www.codechef.com/viewsolution/26706458
i dont know why it showing wrong but it is working.

Whats wrong in this code written in python?

def many(r,p):
b=list()
for m in r:
if r[m]==p:
b.append(m)
return b
def ship(W,E):
greater=0
greaterEle=""
for a in E:
if E[a]>greater and a in W:
greater=E[a]
greaterEle=a
return greaterEle
T=int(input())
for i in range(T):
d=dict()
e=dict()
for j in range(12):
P=input()
Q=P.split()
Q[1]=int(Q[1])
Q[3]=int(Q[3])
if (Q[1]>Q[3]):
d[Q[0]]=d.get(Q[0],0)+3
e[Q[0]]=e.get(Q[0],0)+Q[1]-Q[3]
e[Q[4]]=e.get(Q[4],0)+Q[3]-Q[1]
elif (Q[1]<Q[3]):
d[Q[4]]=d.get(Q[4],0)+3
e[Q[0]]=e.get(Q[0],0)+Q[1]-Q[3]
e[Q[4]]=e.get(Q[4],0)+Q[3]-Q[1]
else:
d[Q[0]]=d.get(Q[0],0)+1
d[Q[4]]=d.get(Q[4],0)+1
l=d
u=d.values()
v=max(u)
t=many(d,v)
if len(t)==1:
print(t[0],end=’ ‘)
del l[t[0]]
u=l.values()
w=max(u)
q=many(l,w)
if len(q)!=1:
print(q[0])
else:
F=ship(q,e)
print(F)
else:
G=ship(t,e)
print(G,end=’ ')
del e[G]
t.remove(G)
H=ship(t,e)
print(H)