結果

問題 No.247 線形計画問題もどき
ユーザー kano_townkano_town
提出日時 2015-07-18 00:13:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 4,134 ms
コンパイル使用メモリ 72,148 KB
実行使用メモリ 58,096 KB
最終ジャッジ日時 2023-09-22 18:36:33
合計ジャッジ時間 8,014 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 119 ms
56,152 KB
testcase_02 AC 127 ms
56,304 KB
testcase_03 AC 120 ms
55,780 KB
testcase_04 AC 121 ms
56,328 KB
testcase_05 AC 120 ms
55,972 KB
testcase_06 AC 120 ms
56,164 KB
testcase_07 AC 119 ms
55,780 KB
testcase_08 AC 119 ms
56,492 KB
testcase_09 AC 118 ms
54,248 KB
testcase_10 AC 118 ms
56,244 KB
testcase_11 AC 122 ms
55,868 KB
testcase_12 AC 120 ms
56,080 KB
testcase_13 AC 120 ms
56,344 KB
testcase_14 AC 120 ms
55,808 KB
testcase_15 AC 122 ms
56,436 KB
testcase_16 AC 120 ms
56,396 KB
testcase_17 WA -
testcase_18 AC 119 ms
55,548 KB
testcase_19 AC 136 ms
56,280 KB
testcase_20 WA -
testcase_21 AC 128 ms
55,952 KB
testcase_22 WA -
testcase_23 AC 130 ms
55,972 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 123 ms
56,136 KB
testcase_27 AC 126 ms
56,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Yukicoder247 {

    int now;
    static boolean ok = false;
    static int res = -1;
    static int[] a;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();
        int n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        // ゴリ押し
        gorigori(n - 1, c, 0);
        System.out.println(res);
    }

    public static void gorigori(int now, int nokori, int num) {
        if (ok || now < 0) return;
        if (nokori % a[now] == 0) {
            res = num + nokori / a[now];
            ok = true;
            return;
        }
        for (int i = nokori / a[now]; i >= 0; i--) {
            gorigori(now - 1, nokori - i * a[now], num + i);
        }
    }
}
0