USACO Bronze 2021 February - Year of the Cow

Authors: Ananth Kashyap, Brad Ma


Official Analysis (C++)

We start by setting Bessie's birth year to 0 (or any value, really). Then, for each new cow given in the input, we find that cow's birth year relative to Bessie.

Implementation

Time Complexity: O(N2)\mathcal{O}(N^2)

C++

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::string;
using std::vector;

Java

import java.io.*;
import java.util.*;
public class YearOfTheCow {
static final String[] ZODIAC = {"Ox", "Tiger", "Rabbit", "Dragon",
"Snake", "Horse", "Goat", "Monkey",
"Rooster", "Dog", "Pig", "Rat"};
Code Snippet: Relation Class (Click to expand)

Python

from typing import NamedTuple
ZODIAC = [
"OX",
"TIGER",
"RABBIT",
"DRAGON",
"SNAKE",
"HORSE",
"GOAT",

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!