結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー | ckawatak |
提出日時 | 2019-04-27 18:56:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 162 ms / 2,000 ms |
コード長 | 1,113 bytes |
コンパイル時間 | 550 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 92,788 KB |
最終ジャッジ日時 | 2024-05-06 17:39:17 |
合計ジャッジ時間 | 4,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,224 KB |
testcase_01 | AC | 40 ms
52,480 KB |
testcase_02 | AC | 39 ms
52,224 KB |
testcase_03 | AC | 39 ms
52,224 KB |
testcase_04 | AC | 39 ms
52,096 KB |
testcase_05 | AC | 39 ms
52,096 KB |
testcase_06 | AC | 38 ms
51,968 KB |
testcase_07 | AC | 36 ms
52,096 KB |
testcase_08 | AC | 36 ms
51,840 KB |
testcase_09 | AC | 35 ms
52,224 KB |
testcase_10 | AC | 35 ms
52,660 KB |
testcase_11 | AC | 37 ms
52,608 KB |
testcase_12 | AC | 37 ms
52,480 KB |
testcase_13 | AC | 42 ms
58,240 KB |
testcase_14 | AC | 43 ms
60,032 KB |
testcase_15 | AC | 37 ms
52,864 KB |
testcase_16 | AC | 48 ms
61,312 KB |
testcase_17 | AC | 55 ms
63,104 KB |
testcase_18 | AC | 62 ms
67,840 KB |
testcase_19 | AC | 66 ms
72,064 KB |
testcase_20 | AC | 76 ms
76,176 KB |
testcase_21 | AC | 36 ms
52,224 KB |
testcase_22 | AC | 102 ms
87,936 KB |
testcase_23 | AC | 148 ms
92,144 KB |
testcase_24 | AC | 109 ms
87,424 KB |
testcase_25 | AC | 152 ms
92,148 KB |
testcase_26 | AC | 154 ms
92,272 KB |
testcase_27 | AC | 162 ms
92,012 KB |
testcase_28 | AC | 159 ms
92,272 KB |
testcase_29 | AC | 147 ms
92,140 KB |
testcase_30 | AC | 159 ms
92,144 KB |
testcase_31 | AC | 157 ms
92,788 KB |
ソースコード
N = int(input()) A = [] B = [] for _ in range(N): pair = list(map(int, input().split())) A.append(pair[0]) B.append(pair[1]) def calc_diffs(n,offset): diffs = [] for i in range(1 << n): diff = 0 for j in range(n): if i & (1<<j): diff = diff + A[j+offset] else: diff = diff - B[j+offset] diffs.append(diff) diffs = list(set(diffs)) return sorted(diffs) def lower_bound(n, ns): left = 0 right = len(ns) while left < right: middle = (left + right)//2 if 0 <= n + ns[middle]: right = middle-1 else: left = middle+1 return right def solve(): if N == 1: return min(A[0], B[0]) ldiffs = calc_diffs(N//2,0) rdiffs = calc_diffs(N-N//2, N//2) mindiff = float('inf') for left in ldiffs: i = lower_bound(left, rdiffs) for j in range(-1,2): index = i+j if 0 <= index < len(rdiffs): mindiff = min(mindiff, abs(left+rdiffs[index])) return mindiff print(solve())