AtCoder Beginner Contest 013

Submission #3979513

Source codeソースコード

import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);

        final long N = nextLong();
        final long H = nextLong();

        final long A = nextLong();
        final long B = nextLong();
        final long C = nextLong();
        final long D = nextLong();
        final long E = nextLong();

        long ans = A * N + 1;

        // H + Bx + Dy - (N - x - y)E > 0
        // (D + E)y + (B + E)x +(H - NE) > 0
        // y > -{(B + E)x + (H - NE)}/(D + E)
        for (int x = 0; x < N + 1; x++) {
            long y =
                (long)(
                -1.0
                * (double)((B + E) * x + (H - N * E))
                / (D + E) + 1.0);

            y = Math.max(y, 0);

            ans = Math.min(ans, A * x + C * (long)y);
        }

        out.println(ans);

        out.flush();
    }

    // FastScanner start
    static final InputStream in = System.in;
    static final byte[] buffer = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;
    static boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    static int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    static boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    static int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    static double nextDouble() {
        return Double.parseDouble(next());
    }
    // FastScanner end
}

Submission

Task問題 C - 節制
User nameユーザ名 ShinjiSHIBATA
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 AC
Score得点 101
Source lengthソースコード長 3370 Byte
File nameファイル名
Exec time実行時間 100 ms
Memory usageメモリ使用量 23380 KB

Test case

Set

Set name Score得点 / Max score Cases
Subtask1 10 / 10 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 30 / 30 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 60 / 60 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 1 / 1 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,sample_1.txt,sample_2.txt,sample_3.txt,sample_4.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01_010.txt AC 73 ms 23252 KB
01_011.txt AC 72 ms 18644 KB
01_020.txt AC 71 ms 19028 KB
01_021.txt AC 72 ms 19156 KB
01_100.txt AC 72 ms 18644 KB
01_101.txt AC 71 ms 17748 KB
01_110.txt AC 73 ms 21460 KB
01_111.txt AC 69 ms 17492 KB
01_200.txt AC 72 ms 18004 KB
01_201.txt AC 73 ms 19796 KB
01_220.txt AC 73 ms 19796 KB
01_221.txt AC 72 ms 18516 KB
01_random01.txt AC 71 ms 20180 KB
01_random02.txt AC 73 ms 21076 KB
01_random03.txt AC 73 ms 19156 KB
01_random04.txt AC 71 ms 17492 KB
01_random05.txt AC 75 ms 18516 KB
01_random06.txt AC 74 ms 20564 KB
01_random07.txt AC 74 ms 18900 KB
01_random08.txt AC 75 ms 18644 KB
01_random09.txt AC 81 ms 21204 KB
01_random10.txt AC 73 ms 19028 KB
02_010.txt AC 70 ms 19284 KB
02_011.txt AC 70 ms 19284 KB
02_020.txt AC 71 ms 22356 KB
02_021.txt AC 72 ms 18260 KB
02_100.txt AC 73 ms 18644 KB
02_101.txt AC 73 ms 21076 KB
02_110.txt AC 72 ms 20692 KB
02_111.txt AC 74 ms 19284 KB
02_200.txt AC 72 ms 18004 KB
02_201.txt AC 72 ms 20948 KB
02_220.txt AC 72 ms 18388 KB
02_221.txt AC 72 ms 18772 KB
02_random01.txt AC 73 ms 16468 KB
02_random02.txt AC 70 ms 21332 KB
02_random03.txt AC 71 ms 19796 KB
02_random04.txt AC 73 ms 18004 KB
02_random05.txt AC 73 ms 18900 KB
02_random06.txt AC 72 ms 22612 KB
02_random07.txt AC 72 ms 18260 KB
02_random08.txt AC 72 ms 22996 KB
02_random09.txt AC 72 ms 18772 KB
02_random10.txt AC 72 ms 21076 KB
03_010.txt AC 72 ms 18388 KB
03_011.txt AC 71 ms 19412 KB
03_012.txt AC 73 ms 21204 KB
03_020.txt AC 72 ms 19796 KB
03_021.txt AC 72 ms 17876 KB
03_022.txt AC 71 ms 18260 KB
03_100.txt AC 72 ms 19156 KB
03_101.txt AC 73 ms 18260 KB
03_102.txt AC 73 ms 17108 KB
03_110.txt AC 73 ms 18132 KB
03_111.txt AC 71 ms 19540 KB
03_112.txt AC 73 ms 18388 KB
03_200.txt AC 71 ms 18388 KB
03_201.txt AC 72 ms 21204 KB
03_202.txt AC 75 ms 20948 KB
03_220.txt AC 73 ms 21076 KB
03_221.txt AC 73 ms 21076 KB
03_222.txt AC 72 ms 17236 KB
03_random01.txt AC 72 ms 17876 KB
03_random02.txt AC 72 ms 20564 KB
03_random03.txt AC 73 ms 18644 KB
03_random04.txt AC 72 ms 20564 KB
03_random05.txt AC 73 ms 19028 KB
03_random06.txt AC 73 ms 18772 KB
03_random07.txt AC 73 ms 18388 KB
03_random08.txt AC 73 ms 21076 KB
03_random09.txt AC 72 ms 17620 KB
03_random10.txt AC 72 ms 20564 KB
03_random11.txt AC 75 ms 20436 KB
03_random12.txt AC 73 ms 21332 KB
03_random13.txt AC 73 ms 18644 KB
03_random14.txt AC 71 ms 21332 KB
03_random15.txt AC 72 ms 20948 KB
03_random16.txt AC 72 ms 15700 KB
03_random17.txt AC 73 ms 20564 KB
03_random18.txt AC 73 ms 22612 KB
03_random19.txt AC 72 ms 19156 KB
03_random20.txt AC 71 ms 19156 KB
04_010.txt AC 90 ms 19668 KB
04_011.txt AC 90 ms 21460 KB
04_020.txt AC 100 ms 20948 KB
04_021.txt AC 89 ms 18132 KB
04_100.txt AC 89 ms 21460 KB
04_101.txt AC 86 ms 17236 KB
04_110.txt AC 97 ms 19540 KB
04_111.txt AC 84 ms 19156 KB
04_200.txt AC 81 ms 21076 KB
04_201.txt AC 74 ms 21204 KB
04_220.txt AC 92 ms 16596 KB
04_221.txt AC 91 ms 22868 KB
04_random01.txt AC 76 ms 18516 KB
04_random02.txt AC 82 ms 20820 KB
04_random03.txt AC 85 ms 23380 KB
04_random04.txt AC 89 ms 18388 KB
04_random05.txt AC 84 ms 20948 KB
sample_1.txt AC 72 ms 20820 KB
sample_2.txt AC 73 ms 19028 KB
sample_3.txt AC 73 ms 20564 KB
sample_4.txt AC 72 ms 16340 KB