結果

問題 No.545 ママの大事な二人の子供
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-15 00:02:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,289 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 78,684 KB
実行使用メモリ 66,392 KB
最終ジャッジ日時 2024-04-16 20:50:36
合計ジャッジ時間 11,659 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 123 ms
41,540 KB
testcase_02 WA -
testcase_03 AC 114 ms
41,572 KB
testcase_04 WA -
testcase_05 AC 124 ms
41,112 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 113 ms
41,608 KB
testcase_11 AC 123 ms
41,644 KB
testcase_12 WA -
testcase_13 AC 136 ms
41,256 KB
testcase_14 WA -
testcase_15 AC 125 ms
41,576 KB
testcase_16 WA -
testcase_17 AC 142 ms
41,672 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
41,576 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] b = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      b[i] = sc.nextLong();
    }
    int med = n / 2;
    ArrayList<Long> list1 = new ArrayList<Long>();
    for(int i = 0; i < (int)Math.pow(2, med); i++) {
      long t = 0;
      for(int j = 0; j <= med; j++) {
        if((i & (1 << j)) != 0) {
          t += a[j];
        } else {
          t -= b[j];
        }
      }
      list1.add(t);
    }
    ArrayList<Long> list2 = new ArrayList<Long>();
    if(n - 1 - med >= 0) {
    for(int i = 0; i < (int)Math.pow(2, n - 1 - med); i++) {
      long t = 0;
      for(int j = 0; j < n - 1 - med; j++) {
        if((i & (1 << j)) != 0) {
          t += a[j + med + 1];
        } else {
          t -= b[j + med + 1];
        }
      }
      list2.add(t);
    }
    } else {
      list2.add((long)0);
    }
    long ans = (long)Math.pow(10, 15);
    for(int i = 0; i < list1.size(); i++) {
      for(int j = 0; j < list2.size(); j++) {
        long v = Math.abs(list1.get(i) + list2.get(j));
        ans = Math.min(ans, v);
      }
    }
    System.out.println(ans);
  }
}
0