Submission #7607080
Source Code Expand
import java.io.*; import java.math.BigInteger; import java.net.Inet4Address; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.function.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; import java.util.Map.Entry; public class Main implements Runnable { static final int MOD = (int) 1e9 + 7; static final int MI = (int) 1e9; static final long ML = (long) 1e18; static final Reader in = new Reader(); static final PrintWriter out = new PrintWriter(System.out); StringBuilder answer = new StringBuilder(); Random random = new Random(751454315315L + System.currentTimeMillis()); public static void main(String[] args) { new Thread(null, new Main(), "persefone", 1 << 28).start(); } @Override public void run() { solve(); printf(); flush(); } void solve() { int n = in.nextInt(); int a = in.nextInt(); int lim = (int) 1e6 * 5; long[] dp = LongStream.range(0, lim + 1).toArray(); for (int i = 1; i <= lim; i++) { for (int j = 2 * i; j <= lim; j += i) { dp[j] = Math.min(dp[j], dp[i] + a + (j - i) / i + 1); } } long ans = ML; for (int i = n; i < dp.length; i++) { ans = Math.min(ans, dp[i]); } } static class DSU { int vertices, connectedComponents; int[] ancestor, rank; public DSU(int vertices) { this.vertices = vertices; this.connectedComponents = vertices; this.ancestor = IntStream.range(0, vertices).toArray(); this.rank = IntStream.generate(() -> 1).limit(vertices).toArray(); } public int find(int vertex) { while (vertex != ancestor[vertex]) { vertex = ancestor[vertex]; } return vertex; } public void merge(int from, int to) { from = find(from); to = find(to); if (from == to) { return; } connectedComponents--; if (rank[from] > rank[to]) { ancestor[to] = from; rank[from] += rank[to]; } else { ancestor[from] = to; rank[to] += rank[from]; } } } void printf() { out.print(answer); } void close() { out.close(); } void flush() { out.flush(); } void printf(Stream<?> str) { str.forEach(o -> add(o, " ")); add("\n"); } void printf(Object... obj) { printf(false, obj); } void printfWithDescription(Object... obj) { printf(true, obj); } private void printf(boolean b, Object... obj) { if (obj.length > 1) { for (int i = 0; i < obj.length; i++) { if (b) add(obj[i].getClass().getSimpleName(), " - "); if (obj[i] instanceof Collection<?>) { printf((Collection<?>) obj[i]); } else if (obj[i] instanceof int[][]) { printf((int[][]) obj[i]); } else if (obj[i] instanceof long[][]) { printf((long[][]) obj[i]); } else if (obj[i] instanceof double[][]) { printf((double[][]) obj[i]); } else printf(obj[i]); } return; } if (b) add(obj[0].getClass().getSimpleName(), " - "); printf(obj[0]); } void printf(Object o) { if (o instanceof int[]) printf(Arrays.stream((int[]) o).boxed()); else if (o instanceof char[]) printf(new String((char[]) o)); else if (o instanceof long[]) printf(Arrays.stream((long[]) o).boxed()); else if (o instanceof double[]) printf(Arrays.stream((double[]) o).boxed()); else if (o instanceof boolean[]) { for (boolean b : (boolean[]) o) add(b, " "); add("\n"); } else add(o, "\n"); } void printf(int[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(long[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(double[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(boolean[]... obj) { for (int i = 0; i < obj.length; i++) printf(obj[i]); } void printf(Collection<?> col) { printf(col.stream()); } <T, K> void add(T t, K k) { if (t instanceof Collection<?>) { ((Collection<?>) t).forEach(i -> add(i, " ")); } else if (t instanceof Object[]) { Arrays.stream((Object[]) t).forEach(i -> add(i, " ")); } else add(t); add(k); } <T> void add(T t) { answer.append(t); } static class Reader { private BufferedReader br; private StringTokenizer st; Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } Reader(String fileName) throws FileNotFoundException { br = new BufferedReader(new FileReader(fileName)); } boolean isReady() throws IOException { return br.ready(); } String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String s = ""; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } }
Submission Info
Submission Time | |
---|---|
Task | E - Cookies |
User | hongquanntct |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 6697 Byte |
Status | WA |
Exec Time | 1118 ms |
Memory | 69972 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | 0 / 500 | ||||||
Status |
|
|
|
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, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | WA | 1086 ms | 69972 KB |
01-02.txt | WA | 1062 ms | 67412 KB |
01-03.txt | WA | 1049 ms | 67664 KB |
01-04.txt | WA | 1063 ms | 68564 KB |
01-05.txt | WA | 1059 ms | 68692 KB |
01-06.txt | WA | 1066 ms | 67412 KB |
01-07.txt | WA | 1070 ms | 67156 KB |
01-08.txt | WA | 1068 ms | 69332 KB |
01-09.txt | WA | 1055 ms | 67156 KB |
01-10.txt | WA | 1061 ms | 69588 KB |
01-11.txt | WA | 1056 ms | 67028 KB |
01-12.txt | WA | 1055 ms | 67156 KB |
01-13.txt | WA | 1039 ms | 67284 KB |
01-14.txt | WA | 1064 ms | 66772 KB |
01-15.txt | WA | 1080 ms | 69716 KB |
01-16.txt | WA | 1070 ms | 66772 KB |
01-17.txt | WA | 1073 ms | 67028 KB |
01-18.txt | WA | 1067 ms | 66888 KB |
01-19.txt | WA | 1057 ms | 69204 KB |
01-20.txt | WA | 1083 ms | 66768 KB |
01-21.txt | WA | 1077 ms | 67412 KB |
01-22.txt | WA | 1118 ms | 68692 KB |
01-23.txt | WA | 1086 ms | 64976 KB |
01-24.txt | WA | 1065 ms | 68820 KB |
01-25.txt | WA | 1116 ms | 67796 KB |
01-26.txt | WA | 1056 ms | 67028 KB |
02-01.txt | WA | 74 ms | 22740 KB |
02-02.txt | WA | 82 ms | 23380 KB |
02-03.txt | WA | 72 ms | 21332 KB |
02-04.txt | WA | 73 ms | 22996 KB |
02-05.txt | WA | 81 ms | 20180 KB |
02-06.txt | WA | 83 ms | 23124 KB |
02-07.txt | WA | 73 ms | 20692 KB |
02-08.txt | WA | 82 ms | 20052 KB |
02-09.txt | WA | 73 ms | 19796 KB |
02-10.txt | WA | 72 ms | 22100 KB |
02-11.txt | WA | 72 ms | 21204 KB |
02-12.txt | WA | 72 ms | 20564 KB |
02-13.txt | WA | 73 ms | 22356 KB |
02-14.txt | WA | 73 ms | 21332 KB |
02-15.txt | WA | 84 ms | 22612 KB |
02-16.txt | WA | 75 ms | 20308 KB |
02-17.txt | WA | 85 ms | 21076 KB |
02-18.txt | WA | 83 ms | 20948 KB |
02-19.txt | WA | 83 ms | 20308 KB |
02-20.txt | WA | 82 ms | 20948 KB |
02-21.txt | WA | 84 ms | 20564 KB |
02-22.txt | WA | 72 ms | 21332 KB |
02-23.txt | WA | 71 ms | 20564 KB |
02-24.txt | WA | 72 ms | 25300 KB |
02-25.txt | WA | 1041 ms | 69844 KB |
02-26.txt | WA | 82 ms | 21460 KB |
02-27.txt | WA | 84 ms | 23124 KB |
02-28.txt | WA | 84 ms | 24148 KB |
02-29.txt | WA | 82 ms | 20692 KB |
02-30.txt | WA | 74 ms | 22996 KB |
02-31.txt | WA | 73 ms | 21204 KB |
02-32.txt | WA | 84 ms | 20436 KB |
02-33.txt | WA | 84 ms | 22996 KB |
02-34.txt | WA | 72 ms | 20820 KB |
02-35.txt | WA | 72 ms | 21204 KB |
02-36.txt | WA | 84 ms | 19668 KB |
02-37.txt | WA | 81 ms | 23252 KB |
02-38.txt | WA | 84 ms | 20820 KB |
02-39.txt | WA | 73 ms | 20180 KB |
02-40.txt | WA | 73 ms | 23252 KB |
sample-01.txt | WA | 1063 ms | 67028 KB |
sample-02.txt | WA | 83 ms | 20308 KB |
sample-03.txt | WA | 1079 ms | 69076 KB |