結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
![]() |
提出日時 | 2020-01-30 16:34:28 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,472 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 78,900 KB |
実行使用メモリ | 61,212 KB |
最終ジャッジ日時 | 2024-09-16 03:38:33 |
合計ジャッジ時間 | 6,680 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 TLE * 1 -- * 41 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); int[] times = new int[n]; for (int i = 0; i < n; i++) { times[i] = Integer.parseInt(br.readLine()); } HashSet<Integer>[] dp= new HashSet[n]; dp[0] = new HashSet<>(); for (int i = 1; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } sum += times[j]; if (sum > t) { break; } } if (sum <= t) { dp[0].add(i); } } for (int i = 1; i <= n; i++) { if (dp[i - 1].contains((1 << n) - 1)) { System.out.println(i); return; } dp[i] = new HashSet<>(); for (int x : dp[i - 1]) { for (int y : dp[0]) { if ((x & y) != 0) { continue; } if (!dp[i - 1].contains(x | y)) { dp[i].add(x | y); } } } } } }