Submission #994952


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	private static void solve() {
		long n = nel();
		long a = nel();
		if (n > 1000000 || a > 1000000) {
			out("114514");
			return;
		}
		LinkedList<Long> q = new LinkedList<Long>();
		List<long[]> states = new ArrayList<long[]>();
		List<long[]> states2 = new ArrayList<long[]>();
		states.add(new long[] { 0, 1 });
		long t = 0;
		while (true) {
			int num = states.size();
			for (int i = 0; i < num; i++) {
				long[] s = states.get(i);
				s[0] += s[1];
			}
			if (t >= a + 1) {
				states.add(new long[] { 0, q.poll() });
				num++;
			}
			Collections.sort(states, (sa, sb) -> {
				int c = -Long.compare(sa[0], sb[0]);
				return c != 0 ? c : -Long.compare(sa[1], sb[1]);
			});
			long max = states.get(0)[0];
			if (max >= n) {
				out(t + 1);
				return;
			}
			if (t >= 1)
				q.offer(max);
			states2.clear();
			for (int i = 0; i < num; i++) {
				long[] s = states.get(i);
				states2.add(s);
//				System.out.println(s[0] + " " + s[1]);
				while (i + 1 < num && s[0] == states.get(i + 1)[0])
					i++;
			}
//			System.out.println("---");
			List<long[]> tmp = states;
			states = states2;
			states2 = tmp;
			t++;
		}
	}

	static int abs(int x) {
		return x < 0 ? -x : x;
	}

	static long abs(long x) {
		return x < 0 ? -x : x;
	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static long min(long a, long b) {
		return a < b ? a : b;
	}

	static int max(int a, int b) {
		return a > b ? a : b;
	}

	static long max(long a, long b) {
		return a > b ? a : b;
	}

	static int clamp(int a, int min, int max) {
		return a < min ? min : a > max ? max : a;
	}

	static long clamp(long a, long min, long max) {
		return a < min ? min : a > max ? max : a;
	}

	static void out(String val) {
		IO.out(val);
	}

	static void out(Object val) {
		IO.out(String.valueOf(val));
	}

	static void out(int val) {
		IO.out(String.valueOf(val));
	}

	static void out(long val) {
		IO.out(String.valueOf(val));
	}

	static void out(char val) {
		IO.out(String.valueOf(val));
	}

	static void out(float val) {
		IO.out(String.valueOf(val));
	}

	static void out(double val) {
		IO.out(String.valueOf(val));
	}

	static void out(boolean val) {
		IO.out(String.valueOf(val));
	}

	static String nes() {
		return IO.next();
	}

	static int nei() {
		return IO.nextInt();
	}

	static long nel() {
		return IO.nextLong();
	}

	static int parseInt(String val) {
		return Integer.parseInt(val);
	}

	static int parseInt(char val) {
		return Integer.parseInt(String.valueOf(val));
	}

	static long parseLong(String val) {
		return Long.parseLong(val);
	}

	public static void main(String[] args) {
		solve();
		IO.flush();
	}
}

final class IO {
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out, false);
	private static final byte[] buffer = new byte[1024];
	private static int ptr = 0;
	private static int len = 0;

	private static boolean hasNextByte() {
		if (ptr < len)
			return true;
		ptr = 0;
		try {
			len = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return len > 0;
	}

	private static int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	static boolean hasNext() {
		byte c;
		while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~'))
			ptr++;
		return hasNextByte();
	}

	static String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (b >= '!' && b <= '~') {
			sb.append((char) b);
			b = readByte();
		}
		return sb.toString();
	}

	static long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static int nextInt() {
		if (!hasNext())
			throw new NoSuchElementException();
		int n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static void out(String val) {
		out.println(val);
	}

	static void flush() {
		out.flush();
	}
}

Submission Info

Submission Time
Task E - Cookies
User saharan
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 5115 Byte
Status WA
Exec Time 884 ms
Memory 72532 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 500 0 / 500
Status
AC × 2
WA × 1
AC × 20
RE × 7
AC × 21
WA × 41
RE × 7
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
dataset1 sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt
dataset2 sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, 02-33.txt, 02-34.txt, 02-35.txt, 02-36.txt, 02-37.txt, 02-38.txt, 02-39.txt, 02-40.txt
Case Name Status Exec Time Memory
01-01.txt RE 856 ms 13776 KB
01-02.txt AC 195 ms 13884 KB
01-03.txt AC 171 ms 13392 KB
01-04.txt AC 184 ms 14024 KB
01-05.txt AC 173 ms 13384 KB
01-06.txt AC 180 ms 13772 KB
01-07.txt AC 174 ms 13256 KB
01-08.txt AC 188 ms 14024 KB
01-09.txt AC 186 ms 13388 KB
01-10.txt AC 211 ms 13900 KB
01-11.txt AC 215 ms 14280 KB
01-12.txt AC 884 ms 72532 KB
01-13.txt AC 758 ms 65632 KB
01-14.txt AC 182 ms 13904 KB
01-15.txt RE 179 ms 13904 KB
01-16.txt AC 179 ms 13640 KB
01-17.txt AC 181 ms 13900 KB
01-18.txt AC 177 ms 13516 KB
01-19.txt AC 171 ms 13256 KB
01-20.txt AC 179 ms 13904 KB
01-21.txt AC 173 ms 13260 KB
01-22.txt RE 179 ms 13780 KB
01-23.txt RE 176 ms 13900 KB
01-24.txt RE 181 ms 14012 KB
01-25.txt RE 180 ms 13764 KB
01-26.txt RE 177 ms 13264 KB
02-01.txt WA 86 ms 8148 KB
02-02.txt WA 88 ms 8020 KB
02-03.txt WA 88 ms 8148 KB
02-04.txt WA 88 ms 8144 KB
02-05.txt WA 88 ms 8148 KB
02-06.txt WA 89 ms 8148 KB
02-07.txt WA 87 ms 8148 KB
02-08.txt WA 88 ms 8012 KB
02-09.txt WA 88 ms 8144 KB
02-10.txt WA 89 ms 8140 KB
02-11.txt WA 88 ms 8148 KB
02-12.txt WA 86 ms 8148 KB
02-13.txt WA 88 ms 8144 KB
02-14.txt WA 88 ms 8140 KB
02-15.txt WA 87 ms 8140 KB
02-16.txt WA 88 ms 8148 KB
02-17.txt WA 88 ms 8148 KB
02-18.txt WA 87 ms 8148 KB
02-19.txt WA 89 ms 8144 KB
02-20.txt WA 99 ms 8148 KB
02-21.txt WA 88 ms 8140 KB
02-22.txt WA 87 ms 8148 KB
02-23.txt WA 88 ms 8140 KB
02-24.txt WA 87 ms 8148 KB
02-25.txt WA 88 ms 8148 KB
02-26.txt WA 88 ms 8144 KB
02-27.txt WA 91 ms 8016 KB
02-28.txt WA 88 ms 8016 KB
02-29.txt WA 88 ms 8144 KB
02-30.txt WA 88 ms 8020 KB
02-31.txt WA 89 ms 8144 KB
02-32.txt WA 87 ms 8148 KB
02-33.txt WA 88 ms 8148 KB
02-34.txt WA 87 ms 8144 KB
02-35.txt WA 88 ms 8144 KB
02-36.txt WA 88 ms 8140 KB
02-37.txt WA 88 ms 8148 KB
02-38.txt WA 88 ms 8148 KB
02-39.txt WA 88 ms 8148 KB
02-40.txt WA 88 ms 8144 KB
sample-01.txt AC 181 ms 13652 KB
sample-02.txt WA 88 ms 8016 KB
sample-03.txt AC 183 ms 13904 KB