結果
問題 | No.733 分身並列コーディング |
ユーザー | kitakitalily |
提出日時 | 2019-10-21 13:11:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 227 ms / 1,500 ms |
コード長 | 5,753 bytes |
コンパイル時間 | 2,010 ms |
コンパイル使用メモリ | 78,396 KB |
実行使用メモリ | 54,228 KB |
最終ジャッジ日時 | 2024-07-02 17:42:40 |
合計ジャッジ時間 | 9,348 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
36,876 KB |
testcase_01 | AC | 50 ms
36,760 KB |
testcase_02 | AC | 50 ms
36,488 KB |
testcase_03 | AC | 188 ms
54,060 KB |
testcase_04 | AC | 211 ms
53,968 KB |
testcase_05 | AC | 179 ms
54,060 KB |
testcase_06 | AC | 50 ms
36,352 KB |
testcase_07 | AC | 214 ms
54,228 KB |
testcase_08 | AC | 218 ms
53,876 KB |
testcase_09 | AC | 138 ms
46,544 KB |
testcase_10 | AC | 74 ms
38,372 KB |
testcase_11 | AC | 75 ms
38,776 KB |
testcase_12 | AC | 50 ms
36,724 KB |
testcase_13 | AC | 51 ms
36,716 KB |
testcase_14 | AC | 96 ms
41,276 KB |
testcase_15 | AC | 72 ms
38,196 KB |
testcase_16 | AC | 50 ms
36,716 KB |
testcase_17 | AC | 50 ms
36,828 KB |
testcase_18 | AC | 77 ms
38,700 KB |
testcase_19 | AC | 123 ms
46,464 KB |
testcase_20 | AC | 128 ms
45,312 KB |
testcase_21 | AC | 94 ms
41,304 KB |
testcase_22 | AC | 188 ms
53,932 KB |
testcase_23 | AC | 94 ms
42,136 KB |
testcase_24 | AC | 93 ms
41,252 KB |
testcase_25 | AC | 51 ms
36,488 KB |
testcase_26 | AC | 49 ms
36,532 KB |
testcase_27 | AC | 66 ms
37,836 KB |
testcase_28 | AC | 152 ms
53,912 KB |
testcase_29 | AC | 190 ms
53,952 KB |
testcase_30 | AC | 182 ms
53,932 KB |
testcase_31 | AC | 206 ms
53,780 KB |
testcase_32 | AC | 81 ms
39,292 KB |
testcase_33 | AC | 96 ms
40,164 KB |
testcase_34 | AC | 77 ms
40,368 KB |
testcase_35 | AC | 84 ms
39,764 KB |
testcase_36 | AC | 80 ms
39,840 KB |
testcase_37 | AC | 83 ms
39,284 KB |
testcase_38 | AC | 201 ms
54,148 KB |
testcase_39 | AC | 207 ms
53,936 KB |
testcase_40 | AC | 217 ms
53,956 KB |
testcase_41 | AC | 92 ms
39,900 KB |
testcase_42 | AC | 97 ms
39,644 KB |
testcase_43 | AC | 79 ms
39,780 KB |
testcase_44 | AC | 227 ms
53,852 KB |
testcase_45 | AC | 197 ms
53,936 KB |
testcase_46 | AC | 193 ms
53,760 KB |
testcase_47 | AC | 172 ms
53,640 KB |
testcase_48 | AC | 199 ms
54,020 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static long mod = 1000000007; static int INF = Integer.MAX_VALUE; static int[] b; static int sz; static int[] sum; public static void main(String[] args){ FastScanner scanner = new FastScanner(); int T = scanner.nextInt(); int n = scanner.nextInt(); int[] t = new int[n]; for(int i = 0; i < n; i++){ t[i] = scanner.nextInt(); } //dp[i][j]:=問題の集合iをj人で解いた時、まだ解いていない問題の時間の合計の最小値 int[][] dp = new int[1<<n][20]; for(int i = 1; i < (1<<n); i++){ for(int j = 0; j < n; j++){ dp[i][j] = INF; } } for(int i = 1; i < (1<<n); i++){ for(int j = 0; j < n; j++){ if(((i>>j) & 1) == 1){ for(int k = 0; k <= n; k++){ dp[i][k] = Math.min(dp[i][k],dp[i^(1<<j)][k]+t[j]); if(dp[i][k] <= T){ dp[i][k+1] = 0; } } } } } for(int i = 0; i <= n; i++){ if(dp[(1<<n)-1][i] == 0){ System.out.println(i); return; } } } public static int upperBound(int[] array, int value) { int low = 0; int high = array.length; int mid; while( low < high ) { mid = ((high - low) >>> 1) + low; // (high + low) / 2 if( array[mid] <= value ) { low = mid + 1; } else { high = mid; } } return low; } public static final int lowerBound(final int[] arr, final int value) { int low = 0; int high = arr.length; int mid; while (low < high){ mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策) if (arr[mid] < value) { low = mid + 1; } else { high = mid; } } return low; } static class BIT{ int n; int[] bit; public BIT(int n){ this.n = n; bit = new int[n+1]; } void add(int idx, int val){ for(int i = idx+1; i <= n; i += i&(-i)) bit[i-1] += val; } int sum(int idx){ int res = 0; for(int i = idx+1; i > 0; i -= i&(-i)) res += bit[i-1]; return res; } int sum(int begin, int end){ if(begin == 0) return sum(end); return sum(end)-sum(begin-1); } } static class Pair implements Comparable<Pair>{ int first, second; Pair(int a, int b){ first = a; second = b; } @Override public boolean equals(Object o){ if (this == o) return true; if (!(o instanceof Pair)) return false; Pair p = (Pair) o; return first == p.first && second == p.second; } @Override public int compareTo(Pair p){ //return first == p.first ? second - p.second : first - p.first; //firstで昇順にソート //return (first == p.first ? second - p.second : first - p.first) * -1; //firstで降順にソート //return second == p.second ? first - p.first : second - p.second;//secondで昇順にソート return (second == p.second ? first - p.first : second - p.second)*-1;//secondで降順にソート //return first * 1.0 / second > p.first * 1.0 / p.second ? 1 : -1; // first/secondの昇順にソート //return first * 1.0 / second < p.first * 1.0 / p.second ? 1 : -1; // first/secondの降順にソート //return second * 1.0 / first > p.second * 1.0 / p.first ? 1 : -1; // second/firstの昇順にソート //return second * 1.0 / first < p.second * 1.0 / p.first ? 1 : -1; // second/firstの降順にソート //return Math.atan2(second, first) > Math.atan2(p.second, p.first) ? 1 : -1; // second/firstの昇順にソート //return first + second > p.first + p.second ? 1 : -1; //first+secondの昇順にソート //return first + second < p.first + p.second ? 1 : -1; //first+secondの降順にソート //return first - second < p.first - p.second ? 1 : -1; //first-secondの降順にソート //return Math.atan2(second,first) > Math.atan2(p.second, p.first) ? 1 : -1; } } private static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} } }