USACO Silver 2019 February - Painting the Barn
Authors: Qi Wang, Nathan Wang, Kevin Sheng
Implementation
Time Complexity:
C++
From the official analysis (with minor modifications):
#include <bits/stdc++.h>using namespace std;const int WIDTH = 1000;int main() {freopen("paintbarn.in", "r", stdin);freopen("paintbarn.out", "w", stdout);int rect_num, paint_req;
Java
import java.io.*;import java.util.*;public class PaintBarn {static final int WIDTH = 1000;public static void main(String[] args) throws IOException {Kattio io = new Kattio("paintbarn");int rectNum = io.nextInt();int paintReq = io.nextInt();int[][] barn = new int[WIDTH + 1][WIDTH + 1];
Python
WIDTH = 1000barn = [[0 for _ in range(WIDTH + 1)] for _ in range(WIDTH + 1)]with open("paintbarn.in") as read:rect_num, paint_req = [int(i) for i in read.readline().split()]for _ in range(rect_num):start_x, start_y, end_x, end_y = [int(i) for i in read.readline().split()]# Set up the prefix sums array with all the corners of the given rectanglebarn[start_x][start_y] += 1barn[start_x][end_y] -= 1
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!