USACO Bronze 2015 December - Contaminated Milk

Author: Jesse Choe

Official Analysis

C++

In this problem, we are asked to find how many people are sick based on what type of milk each person drank, when they drank it, and when a person got sick. To solve this problem, we must find the types of milk that could (potentially) make a person sick. To do this, we must check if a person drank milk type X before they became sick. Therefore, we loop over every sick person and store the possible milk types in a 2D array of integers. Then, we loop over all the possible milk types for every sick person and check for commonalities. If there is consistency in the possible milk types (every sick person), then we add that to an array and consider it one of the possible types of milk that would make someone sick. After this, we check how many people drank one of the possible milk types (consistent with each sick person), and print the number of people who were sick.

#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0)
#define len(x) (int)(x).length()
void setIO(string fileName = ""){
FastIO;
if(len(fileName)){

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!