結果
問題 | No.393 2本の竹 |
ユーザー |
|
提出日時 | 2016-07-12 23:43:38 |
言語 | Java17 (openjdk 17.0.1) |
結果 |
AC
|
実行時間 | 200 ms / 1,000 ms |
コード長 | 2,286 bytes |
コンパイル時間 | 3,286 ms |
使用メモリ | 38,812 KB |
最終ジャッジ日時 | 2022-12-14 14:29:16 |
合計ジャッジ時間 | 7,360 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
35,084 KB |
testcase_01 | AC | 59 ms
34,504 KB |
testcase_02 | AC | 67 ms
34,204 KB |
testcase_03 | AC | 79 ms
34,184 KB |
testcase_04 | AC | 61 ms
34,448 KB |
testcase_05 | AC | 65 ms
34,500 KB |
testcase_06 | AC | 61 ms
35,916 KB |
testcase_07 | AC | 88 ms
34,196 KB |
testcase_08 | AC | 93 ms
36,664 KB |
testcase_09 | AC | 200 ms
38,580 KB |
testcase_10 | AC | 98 ms
36,552 KB |
testcase_11 | AC | 124 ms
38,564 KB |
testcase_12 | AC | 142 ms
38,812 KB |
testcase_13 | AC | 136 ms
38,400 KB |
testcase_14 | AC | 99 ms
36,772 KB |
testcase_15 | AC | 60 ms
35,900 KB |
testcase_16 | AC | 63 ms
35,904 KB |
testcase_17 | AC | 78 ms
35,072 KB |
testcase_18 | AC | 68 ms
35,880 KB |
testcase_19 | AC | 57 ms
34,584 KB |
testcase_20 | AC | 61 ms
35,620 KB |
testcase_21 | AC | 81 ms
34,268 KB |
testcase_22 | AC | 155 ms
38,812 KB |
testcase_23 | AC | 95 ms
38,792 KB |
testcase_24 | AC | 68 ms
34,144 KB |
testcase_25 | AC | 61 ms
35,012 KB |
testcase_26 | AC | 59 ms
35,884 KB |
testcase_27 | AC | 194 ms
37,288 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); } } }