結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-03 20:54:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 324 ms / 1,000 ms |
| コード長 | 1,293 bytes |
| コンパイル時間 | 2,243 ms |
| コンパイル使用メモリ | 78,424 KB |
| 実行使用メモリ | 46,544 KB |
| 最終ジャッジ日時 | 2024-11-08 05:31:14 |
| 合計ジャッジ時間 | 8,855 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int d = sc.nextInt();
if (d <= 0 || d > 10)
throw new AssertionError();
for (; d > 0; d--) {
new Main().solver();
}
}
void solver() {
int n1 = sc.nextInt();
int n2 = sc.nextInt();
if (n1 < 0 || n1 > 100000 || n2 < 0 || n2 > 100000) {
throw new AssertionError();
}
int m = sc.nextInt();
if (m <= 0 || m > 60)
throw new AssertionError();
int[] a = new int[m];
for (int i = 0; i < m; i++) {
a[i] = sc.nextInt();
if (a[i] > 100000 || a[i] <= 0)
throw new AssertionError();
}
Arrays.sort(a);
boolean[] from = new boolean[n1 + 1];
from[0] = true;
int len = 0;
for (int i = 0; i < m; i++) {
boolean[] to = new boolean[100001];
boolean f = false;
for (int j = 0; j <= n1; j++) {
if (from[j]) {
if (j + a[i] <= n1) {
to[j + a[i]] = true;
f = true;
}
if ((len - j) + a[i] <= n2) {
to[j] = true;
f = true;
}
}
}
len += a[i];
from = to;
if (!f) {
System.out.println(i);
return;
}
}
System.out.println(m);
}
void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
}