Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws Exception {
- long time = System.nanoTime();
- int n = 100000;
- int[] x = new int[n];
- for(int i = 0; i < n; i++){
- x[i] = n-i;
- }
- int[] next = new int[n];
- for (int i = 0; i < n - 1; i++) next[i] = i + 1;
- next[n - 1] = -1;
- int count = 0;
- ArrayList<Integer> eat = new ArrayList<Integer>();
- for (int i = 0; i < n; i++) eat.add(i);
- while (true) {
- ArrayList<Integer> neweat = new ArrayList<Integer>();
- for (int start : eat) {
- boolean flag = false;
- int xx = start;
- while (true) {
- int yy = next[xx];
- if (yy == -1 || x[yy] > x[xx]) {
- next[start] = yy;
- break;
- }
- xx = yy;
- flag = true;
- }
- if (flag) neweat.add(start);
- }
- if (neweat.size() != 0) count++;
- else break;
- eat = neweat;
- // System.out.println(eat.size());
- }
- out.println(count);
- /// System.out.println((System.nanoTime() - time)* 1e-9);
- out.close();
- }
- static PrintWriter out = new PrintWriter(System.out);
- static BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
- static StringTokenizer in = new StringTokenizer("");
- static String nextToken() throws Exception {
- if (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());
- return in.nextToken();
- }
- static int next() throws Exception {return Integer.parseInt(nextToken());};
- static int[] next(int n) throws Exception {
- int[] x = new int[n];
- for (int i = 0; i < n; i++) x[i] = next();
- return x;
- }
- static int[][] next(int n, int m) throws Exception {
- int[][] x = new int[n][];
- for (int i = 0; i < n; i++) x[i] = next(m);
- return x;
- }
- static long nextl() throws Exception {return Long.parseLong(nextToken());};
- static long[] nextl(int n) throws Exception {
- long[] x = new long[n];
- for (int i = 0; i < n; i++) x[i] = nextl();
- return x;
- }
- static long[][] nextl(int n, int m) throws Exception {
- long[][] x = new long[n][];
- for (int i = 0; i < n; i++) x[i] = nextl(m);
- return x;
- }
- static double nextd() throws Exception {return Double.parseDouble(nextToken());};
- static double[] nextd(int n) throws Exception {
- double[] x = new double[n];
- for (int i = 0; i < n; i++) x[i] = nextd();
- return x;
- }
- static double[][] nextd(int n, int m) throws Exception {
- double[][] x = new double[n][];
- for (int i = 0; i < n; i++) x[i] = nextd(m);
- return x;
- }
- static String nextline() throws Exception {
- in = new StringTokenizer("");
- return bufferedreader.readLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement