結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー |
![]() |
提出日時 | 2020-09-08 12:51:35 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 739 bytes |
コンパイル時間 | 2,428 ms |
コンパイル使用メモリ | 79,524 KB |
実行使用メモリ | 174,156 KB |
最終ジャッジ日時 | 2024-11-29 11:50:32 |
合計ジャッジ時間 | 8,364 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 WA * 8 RE * 3 |
ソースコード
import java.util.*;public class Main {public static void main (String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();long[] adds = new long[n];long[] dp = new long[1 << n];for (int i = 0; i < n; i++) {long a = sc.nextLong();long b = sc.nextLong();dp[0] += b;adds[i] = a + b;}long min = dp[0];for (int i = 1; i < (1 << n); i++) {for (int j = 0; j < n; j++) {if ((i & (1 << j)) != (1 << j)) {continue;}dp[i] = dp[i ^ (1 << j)] - adds[j];break;}min = Math.min(min, Math.abs(dp[i]));}System.out.println(min);}}