結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
|
提出日時 | 2015-07-18 00:13:53 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 906 bytes |
コンパイル時間 | 2,994 ms |
コンパイル使用メモリ | 75,832 KB |
実行使用メモリ | 54,396 KB |
最終ジャッジ日時 | 2024-07-08 09:49:39 |
合計ジャッジ時間 | 7,157 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 17 WA * 6 |
ソースコード
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); } } }