Chances of Winning
InterviewTime limit1sMemory limit128 MB
Given results of some games among four teams, count the outcomes of the remaining games where team T ends with strictly more points than every other team.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation, Simulation, Combinatorics
- Solved
- No attempts yet
Problem
You want to find out the chances that your favourite team becomes the champion of a small tournament.
There are exactly four teams. By the end of the tournament, six games will have been played, with each team playing every other team exactly once. Each game either has one team win and the other lose, or ends in a tie. If a game is not a tie, the winning team is awarded points and the losing team . If the game is a tie, each team is awarded point.
Your favourite team becomes the champion only if it finishes with strictly more total points than every other team. In other words, being tied for first place is not good enough.
The tournament is not over yet, but you know the results of every game that has already been played. Considering all possible ways points could be awarded in the remaining, not-yet-played games, determine in how many of those cases your favourite team is the champion.
Input
The first line contains an integer , your favourite team (). The second line contains an integer , the number of games already played (). Each of the next lines describes a played game with four space-separated integers , , , ( and ). This means team (with score ) played team (with score ): team won if , team won if , and the game was a tie if . No pair of teams plays twice, so the pairs given in the input are all distinct.
Output
Output a single integer: the number of ways, over all possible outcomes of the remaining games, in which team is the tournament champion.