We'll start by saying that for each in range , . For all other values of , we are given for , or for . We will then check if these values of produce a valid permutation.
Since , we can simulate this process for every possible starting cow and pick the first valid permutation (since that would be the lexicographical minimum).
Implementation
Time Complexity:
import java.io.*;import java.util.*;public class Photoshoot {public static void main(String[] args) throws IOException {Kattio io = new Kattio("photo");int N = io.nextInt();int[] bessieList = new int[N];int[] correctList = new int[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!