Solution 1

Official Analysis

Solution 2 - Generating All Permutations

We can map the games to every possible permutation of the moves (hoof, paper, scissors) and find the sequence which gives us the maximum wins. This works because 1N1001 \leq N \leq 100.

Implementation

Time Complexity: O(N)\mathcal{O}(N)

Python

from itertools import permutations
import sys
sys.stdin = open("hps.in", "r")
sys.stdout = open("hps.out", "w")
n = int(input())
games = []
games = [list(map(int, input().split())) for _ in range(n)]

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!