Official Analysis (C++)

Implementation

Time Complexity: O(NMlogR)\mathcal{O}(NM\log R), where RR denotes the maximum height difference between any two cells

Java

import java.io.*;
import java.util.*;
public class CrossCountrySkiing {
static int n, m;
static int startI, startJ; // Stores starting position of each floodfill
static int[][] course; // Stores the skiing course heights
static boolean[][] waypoints; // Stored as booleans instead of 1s and 0s
static boolean[][] vis; // Visited array for floodfill

C++

#include <bits/stdc++.h>
using namespace std;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
constexpr int MAX_N = 500;
int m, n;
int wy, wx;

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!