結果
問題 | No.393 2本の竹 |
ユーザー | Grenache |
提出日時 | 2016-07-12 23:43:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 205 ms / 1,000 ms |
コード長 | 2,286 bytes |
コンパイル時間 | 4,581 ms |
コンパイル使用メモリ | 84,144 KB |
実行使用メモリ | 41,664 KB |
最終ジャッジ日時 | 2024-11-08 05:45:53 |
合計ジャッジ時間 | 7,058 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 86 ms
38,312 KB |
testcase_01 | AC | 56 ms
36,904 KB |
testcase_02 | AC | 62 ms
37,216 KB |
testcase_03 | AC | 78 ms
37,684 KB |
testcase_04 | AC | 55 ms
37,356 KB |
testcase_05 | AC | 57 ms
37,396 KB |
testcase_06 | AC | 54 ms
37,200 KB |
testcase_07 | AC | 84 ms
37,928 KB |
testcase_08 | AC | 93 ms
38,396 KB |
testcase_09 | AC | 205 ms
41,608 KB |
testcase_10 | AC | 90 ms
38,748 KB |
testcase_11 | AC | 128 ms
40,484 KB |
testcase_12 | AC | 145 ms
41,576 KB |
testcase_13 | AC | 117 ms
39,988 KB |
testcase_14 | AC | 82 ms
38,688 KB |
testcase_15 | AC | 57 ms
37,232 KB |
testcase_16 | AC | 57 ms
37,228 KB |
testcase_17 | AC | 80 ms
38,188 KB |
testcase_18 | AC | 59 ms
37,336 KB |
testcase_19 | AC | 53 ms
37,252 KB |
testcase_20 | AC | 53 ms
37,368 KB |
testcase_21 | AC | 78 ms
37,808 KB |
testcase_22 | AC | 155 ms
41,664 KB |
testcase_23 | AC | 101 ms
39,228 KB |
testcase_24 | AC | 61 ms
37,172 KB |
testcase_25 | AC | 55 ms
36,888 KB |
testcase_26 | AC | 54 ms
37,264 KB |
testcase_27 | AC | 184 ms
40,808 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder393 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int d = sc.nextInt(); for (int tcase = 0; tcase < d; tcase++) { int n1 = sc.nextInt(); int n2 = sc.nextInt(); int n = n1 + n2; n1 = Math.min(n1, n2); int m = sc.nextInt(); int[] a = new int[m]; for (int i = 0; i < m; i++) { a[i] = sc.nextInt(); } Arrays.sort(a); int[] sum = new int[m + 1]; for (int i = 1; i <= m; i++) { sum[i] = sum[i - 1] + a[i - 1]; } int tmp = Arrays.binarySearch(sum, n); int ret = tmp >= 0 ? tmp : -(tmp + 1) - 1; int ok = n1 - (n - sum[ret]); BitSet bs = new BitSet(n1 + 1); bs.set(0); for (int i = 0; i < ret; i++) { for (int j = bs.length(); (j = bs.previousSetBit(j - 1)) >= 0; ) { if (j + a[i] > n1) { continue; } else { bs.set(j + a[i]); } } } if (bs.previousSetBit(bs.length() - 1) >= ok) { pr.println(ret); } else { pr.println(ret - 1); } } sc.close(); pr.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }