Submission #213840
Source Code Expand
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.*; public class Main { private static final int mod = (int)1e9+7; final Random random = new Random(0); final IOFast io = new IOFast(); /// MAIN CODE public void run() throws IOException { // int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim()); int TEST_CASE = 1; while(TEST_CASE-- != 0) { int n = io.nextInt(); long h = io.nextLong(); long a = io.nextLong(); long b = io.nextLong(); long c = io.nextLong(); long d = io.nextLong(); long e = io.nextLong(); long ans = Long.MAX_VALUE; for(int i = 0; i <= n; i++) { long rest = h - e * (n - i); long val = rest + b * i; long j = Math.max(0, (-val + (d + e)) / (d + e)); long v = a * i + c * j; // System.err.println(i + " " + j + " " + val); if(i + j > n) continue; ans = Math.min(ans, v); } io.out.println(ans); } } /// TEMPLATE static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); } static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); } static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; } static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; } static void radixSort(int[] xs) { int[] cnt = new int[(1<<16)+1]; int[] ys = new int[xs.length]; for(int j = 0; j <= 16; j += 16) { Arrays.fill(cnt, 0); for(int x : xs) { cnt[(x>>j&0xFFFF)+1]++; } for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; } for(int x : xs) { ys[cnt[x>>j&0xFFFF]++] = x; } { final int[] t = xs; xs = ys; ys = t; } } } static void radixSort(long[] xs) { int[] cnt = new int[(1<<16)+1]; long[] ys = new long[xs.length]; for(int j = 0; j <= 48; j += 16) { Arrays.fill(cnt, 0); for(long x : xs) { cnt[(int)(x>>j&0xFFFF)+1]++; } for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; } for(long x : xs) { ys[cnt[(int)(x>>j&0xFFFF)]++] = x; } { final long[] t = xs; xs = ys; ys = t; } } } static void arrayIntSort(int[][] x, int... keys) { Arrays.sort(x, new ArrayIntsComparator(keys)); } static class ArrayIntsComparator implements Comparator<int[]> { final int[] KEY; public ArrayIntsComparator(int... key) { KEY = key; } @Override public int compare(int[] o1, int[] o2) { for(int k : KEY) if(o1[k] != o2[k]) return o1[k] - o2[k]; return 0; } } static class ArrayIntComparator implements Comparator<int[]> { final int KEY; public ArrayIntComparator(int key) { KEY = key; } @Override public int compare(int[] o1, int[] o2) { return o1[KEY] - o2[KEY]; } } void main() throws IOException { // IOFast.setFileIO("rle-size.in", "rle-size.out"); try { run(); } catch (EndOfFileRuntimeException e) { } io.out.flush(); } public static void main(String[] args) throws IOException { new Main().main(); } static class EndOfFileRuntimeException extends RuntimeException { private static final long serialVersionUID = -8565341110209207657L; } static public class IOFast { private BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private PrintWriter out = new PrintWriter(System.out); void setFileIO(String ins, String outs) throws IOException { out.flush(); out.close(); in.close(); in = new BufferedReader(new FileReader(ins)); out = new PrintWriter(new FileWriter(outs)); System.err.println("reading from " + ins); } // private static final int BUFFER_SIZE = 50 * 200000; private static int pos, readLen; private static final char[] buffer = new char[1024 * 8]; private static char[] str = new char[500*8*2]; private static boolean[] isDigit = new boolean[256]; private static boolean[] isSpace = new boolean[256]; private static boolean[] isLineSep = new boolean[256]; static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; } public int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; } public int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; // return Integer.parseInt(nextString()); } public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; // return Long.parseLong(nextString()); } public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } } int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); // str[len++] = (char)read(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); } public String nextString() throws IOException { return new String(next()); } public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); } public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; } public double nextDouble() throws IOException { return Double.parseDouble(nextString()); } public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; } public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; } public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; } } }
Submission Info
Submission Time | |
---|---|
Task | C - 節制 |
User | tanzaku |
Language | Java (OpenJDK 1.7.0) |
Score | 101 |
Code Size | 7972 Byte |
Status | AC |
Exec Time | 1060 ms |
Memory | 21944 KB |
Judge Result
Set Name | Subtask1 | Subtask2 | Subtask3 | Subtask4 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 10 / 10 | 30 / 30 | 60 / 60 | 1 / 1 | ||||||||
Status |
|
|
|
|
Set Name | Test Cases |
---|---|
Subtask1 | sample_1.txt, sample_2.txt, sample_3.txt, 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt |
Subtask2 | sample_1.txt, sample_2.txt, sample_3.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt |
Subtask3 | sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt, 03_010.txt, 03_011.txt, 03_012.txt, 03_020.txt, 03_021.txt, 03_022.txt, 03_100.txt, 03_101.txt, 03_102.txt, 03_110.txt, 03_111.txt, 03_112.txt, 03_200.txt, 03_201.txt, 03_202.txt, 03_220.txt, 03_221.txt, 03_222.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt, 03_random16.txt, 03_random17.txt, 03_random18.txt, 03_random19.txt, 03_random20.txt |
Subtask4 | 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt, 03_010.txt, 03_011.txt, 03_012.txt, 03_020.txt, 03_021.txt, 03_022.txt, 03_100.txt, 03_101.txt, 03_102.txt, 03_110.txt, 03_111.txt, 03_112.txt, 03_200.txt, 03_201.txt, 03_202.txt, 03_220.txt, 03_221.txt, 03_222.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt, 03_random16.txt, 03_random17.txt, 03_random18.txt, 03_random19.txt, 03_random20.txt, 04_010.txt, 04_011.txt, 04_020.txt, 04_021.txt, 04_100.txt, 04_101.txt, 04_110.txt, 04_111.txt, 04_200.txt, 04_201.txt, 04_220.txt, 04_221.txt, 04_random01.txt, 04_random02.txt, 04_random03.txt, 04_random04.txt, 04_random05.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01_010.txt | AC | 431 ms | 20784 KB |
01_011.txt | AC | 385 ms | 20660 KB |
01_020.txt | AC | 400 ms | 20788 KB |
01_021.txt | AC | 386 ms | 20656 KB |
01_100.txt | AC | 389 ms | 20656 KB |
01_101.txt | AC | 384 ms | 20784 KB |
01_110.txt | AC | 385 ms | 20788 KB |
01_111.txt | AC | 388 ms | 20776 KB |
01_200.txt | AC | 389 ms | 20788 KB |
01_201.txt | AC | 384 ms | 20788 KB |
01_220.txt | AC | 391 ms | 20780 KB |
01_221.txt | AC | 385 ms | 20656 KB |
01_random01.txt | AC | 387 ms | 20660 KB |
01_random02.txt | AC | 390 ms | 20788 KB |
01_random03.txt | AC | 382 ms | 20776 KB |
01_random04.txt | AC | 389 ms | 20656 KB |
01_random05.txt | AC | 381 ms | 20788 KB |
01_random06.txt | AC | 389 ms | 20660 KB |
01_random07.txt | AC | 381 ms | 20660 KB |
01_random08.txt | AC | 384 ms | 20788 KB |
01_random09.txt | AC | 388 ms | 20784 KB |
01_random10.txt | AC | 385 ms | 20748 KB |
02_010.txt | AC | 384 ms | 20748 KB |
02_011.txt | AC | 385 ms | 20788 KB |
02_020.txt | AC | 384 ms | 20784 KB |
02_021.txt | AC | 386 ms | 20752 KB |
02_100.txt | AC | 389 ms | 20780 KB |
02_101.txt | AC | 382 ms | 20656 KB |
02_110.txt | AC | 387 ms | 20756 KB |
02_111.txt | AC | 384 ms | 20656 KB |
02_200.txt | AC | 382 ms | 20656 KB |
02_201.txt | AC | 378 ms | 20660 KB |
02_220.txt | AC | 382 ms | 20776 KB |
02_221.txt | AC | 387 ms | 20760 KB |
02_random01.txt | AC | 381 ms | 20700 KB |
02_random02.txt | AC | 381 ms | 20656 KB |
02_random03.txt | AC | 382 ms | 20656 KB |
02_random04.txt | AC | 385 ms | 20772 KB |
02_random05.txt | AC | 380 ms | 20788 KB |
02_random06.txt | AC | 381 ms | 20788 KB |
02_random07.txt | AC | 384 ms | 20788 KB |
02_random08.txt | AC | 406 ms | 20660 KB |
02_random09.txt | AC | 1060 ms | 20732 KB |
02_random10.txt | AC | 395 ms | 20776 KB |
03_010.txt | AC | 416 ms | 20776 KB |
03_011.txt | AC | 392 ms | 20780 KB |
03_012.txt | AC | 381 ms | 20660 KB |
03_020.txt | AC | 408 ms | 20784 KB |
03_021.txt | AC | 382 ms | 20788 KB |
03_022.txt | AC | 386 ms | 20784 KB |
03_100.txt | AC | 391 ms | 20788 KB |
03_101.txt | AC | 381 ms | 20776 KB |
03_102.txt | AC | 394 ms | 20788 KB |
03_110.txt | AC | 379 ms | 20788 KB |
03_111.txt | AC | 380 ms | 20784 KB |
03_112.txt | AC | 394 ms | 20784 KB |
03_200.txt | AC | 414 ms | 20784 KB |
03_201.txt | AC | 409 ms | 20780 KB |
03_202.txt | AC | 415 ms | 20652 KB |
03_220.txt | AC | 387 ms | 20784 KB |
03_221.txt | AC | 393 ms | 20788 KB |
03_222.txt | AC | 394 ms | 20788 KB |
03_random01.txt | AC | 391 ms | 20784 KB |
03_random02.txt | AC | 388 ms | 20700 KB |
03_random03.txt | AC | 385 ms | 20656 KB |
03_random04.txt | AC | 385 ms | 20660 KB |
03_random05.txt | AC | 405 ms | 20660 KB |
03_random06.txt | AC | 406 ms | 20660 KB |
03_random07.txt | AC | 406 ms | 20788 KB |
03_random08.txt | AC | 392 ms | 20780 KB |
03_random09.txt | AC | 400 ms | 20784 KB |
03_random10.txt | AC | 384 ms | 20788 KB |
03_random11.txt | AC | 383 ms | 20660 KB |
03_random12.txt | AC | 387 ms | 20788 KB |
03_random13.txt | AC | 383 ms | 20784 KB |
03_random14.txt | AC | 393 ms | 20652 KB |
03_random15.txt | AC | 415 ms | 20688 KB |
03_random16.txt | AC | 409 ms | 20788 KB |
03_random17.txt | AC | 416 ms | 20784 KB |
03_random18.txt | AC | 395 ms | 20656 KB |
03_random19.txt | AC | 385 ms | 20780 KB |
03_random20.txt | AC | 384 ms | 20780 KB |
04_010.txt | AC | 418 ms | 21904 KB |
04_011.txt | AC | 409 ms | 21648 KB |
04_020.txt | AC | 414 ms | 21944 KB |
04_021.txt | AC | 422 ms | 21940 KB |
04_100.txt | AC | 413 ms | 21932 KB |
04_101.txt | AC | 751 ms | 21936 KB |
04_110.txt | AC | 419 ms | 21804 KB |
04_111.txt | AC | 411 ms | 21940 KB |
04_200.txt | AC | 410 ms | 21940 KB |
04_201.txt | AC | 391 ms | 20788 KB |
04_220.txt | AC | 409 ms | 21772 KB |
04_221.txt | AC | 413 ms | 21812 KB |
04_random01.txt | AC | 403 ms | 21092 KB |
04_random02.txt | AC | 412 ms | 21940 KB |
04_random03.txt | AC | 410 ms | 21940 KB |
04_random04.txt | AC | 440 ms | 21940 KB |
04_random05.txt | AC | 421 ms | 21940 KB |
sample_1.txt | AC | 386 ms | 20792 KB |
sample_2.txt | AC | 384 ms | 20660 KB |
sample_3.txt | AC | 382 ms | 20788 KB |
sample_4.txt | AC | 386 ms | 20784 KB |