UCRPC F21 C - Maths of Glory

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem type

Defeat your rivals with superior numbers!

Aim for the 6!

Maths of Glory is a 2v2. minigame in Super Mario Party, and you can view how the game is actually played here. Each team has a castle that is made up of n jigsaw pieces, and a cannon that can fire cannonballs at the rival's castle. The goal is to destroy the castle of your rival.

In each round, each player will hit a slot with numbers ranging from 1 to 6. The numbers from the two players in the same team will be multiplied to be the points p earned in the current round. Then the cannon will fire at the rival's castle and destroy p jigsaw pieces of the castle. The first team to demolish the opposing team's castle entirely won the game. Note that if two teams both win at the same round, the game ends in a tie.

Given the numbers each player hits in each round, write a program to determine which team wins the game.

Input Specification

The first line of the input contains two integers, n (0 < n \le 10^6), is the number of jigsaw pieces in each castle, and m, which means there will be m rounds of game shown below. The next m (0 < m \le 10^6) lines each contain 4 numbers, which is the number hit by player 1, player 2, player 3 and player 4. Player 1 and 2 are in a team, and player 3 and 4 are in a team. The 4 numbers are guaranteed to be in the range of 1 to 6.

Output Specification

Output the winning team and when they win. For example, if team 1 wins at round 5, output Team 1 wins at round 5!.

If they both win at a certain round x, output It's a tie at round x!.

If the game ends with neither team winning, output Oh no!.

Sample Input 1

20 6
2 4 6 3
3 3 1 5
5 2 2 1
1 1 1 1
6 3 1 4
2 6 4 1

Sample Output 1

Team 2 wins at round 2!

Sample Input 2

30 6
2 4 6 3
3 3 1 5
5 2 2 1
1 1 1 1
6 3 1 4
2 6 4 1

Sample Output 2

It's a tie at round 5!

Sample Input 3

100 6
2 4 6 3
3 3 1 5
5 2 2 1
1 1 1 1
6 3 1 4
2 6 4 1

Sample Output 3

Oh no!

Explanation for Sample Outputs

For the first test case, after round 2, team one earns 17 points and team 2 earns 23 points. Since both castles only have 20 pieces each, team 2 will win.

For the second test case, there are 30 pieces in each castle and both teams reach 30 points or more at round 5 (46 vs 30). As a result, it's a tie.

For the third test case, after 6 rounds, team 1 earns 58 points and team 2 earns 32 points. Neither of them achieved 100 points to defeat the other team. As a result, you need to output Oh no!.

Source of pictures and descriptions: https://www.mariowiki.com/Maths_of_Glory. You can also find more details about the game from this site.

Scoring

There are 20 test cases, 3 points each.


Comments

There are no comments at the moment.