USACO Silver 2019 January - Icy Perimeter
Authors: Tanish Tyagi, Brad Ma, Juheon Rhee
Implementation
Time Complexity:
Java
import java.io.*;import java.util.*;public class IcyPerimeter {public static void main(String[] args) throws IOException {Kattio io = new Kattio("perimeter");n = io.nextInt();// we do n + 2 because there is an extra outer ring for flood fillnumberedMatrix = new int[n + 2][n + 2];
C++
// created by Tanish Tyagi#include <bits/stdc++.h>using namespace std;using ll = long long;const int MAXN = 1005;char grid[MAXN][MAXN]; // the grid itselfint n;
Python
# This solution does TLE on the USACO website on one test case because python is slow.from collections import dequewith open("perimeter.in") as r:t = r.readlinen = int(t())ice = []visited = [[False] * n for _ in range(n)]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!