Submission #541304

#TimeUsernameProblemLanguageResultExecution timeMemory
541304AstollfoRabbit Carrot (LMIO19_triusis)Java
100 / 100
276 ms23496 KiB
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.ArrayList; public class triusis { // any other name breaks the grader lmao public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer inital = new StringTokenizer(read.readLine()); int poleNum = Integer.parseInt(inital.nextToken()); int jumpHeight = Integer.parseInt(inital.nextToken()); ArrayList<Integer> possUnchanged = new ArrayList<>(); for (int p = 0; p < poleNum; p++) { int pole = Integer.parseInt(read.readLine()); // only add if it has any hope of being unchanged if ((p + 1) * jumpHeight >= pole) { possUnchanged.add((p + 1) * jumpHeight - pole); } } System.out.println(poleNum - longestNondecSubseq(possUnchanged)); } private static int longestNondecSubseq(ArrayList<Integer> arr) { ArrayList<Integer> minEndings = new ArrayList<>(); for (int i : arr) { // find the latest spot we can insert it (because it just has to be nondecreasing) int pos = bisectRight(minEndings, i); // standard LIS protocol if (pos == minEndings.size()) { minEndings.add(i); } else { minEndings.set(pos, i); } } return minEndings.size(); } private static int bisectRight(ArrayList<Integer> arr, int x) { int lo = 0; int hi = arr.size(); while (lo < hi) { int mid = (lo + hi) / 2; if (x < arr.get(mid)) { hi = mid; } else { lo = mid + 1; } } return lo; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...