結果

問題 No.545 ママの大事な二人の子供
ユーザー mkawa2mkawa2
提出日時 2020-05-21 18:23:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,667 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 23,512 KB
最終ジャッジ日時 2024-04-09 23:27:19
合計ジャッジ時間 3,188 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 29 ms
10,880 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 RE -
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 28 ms
11,008 KB
testcase_11 AC 26 ms
10,880 KB
testcase_12 AC 28 ms
10,880 KB
testcase_13 AC 28 ms
10,880 KB
testcase_14 AC 26 ms
10,880 KB
testcase_15 AC 27 ms
11,008 KB
testcase_16 AC 28 ms
11,008 KB
testcase_17 RE -
testcase_18 AC 33 ms
11,264 KB
testcase_19 AC 34 ms
11,724 KB
testcase_20 RE -
testcase_21 AC 27 ms
11,008 KB
testcase_22 RE -
testcase_23 AC 172 ms
23,512 KB
testcase_24 RE -
testcase_25 AC 163 ms
22,936 KB
testcase_26 AC 165 ms
22,860 KB
testcase_27 AC 160 ms
23,372 KB
testcase_28 RE -
testcase_29 AC 163 ms
23,500 KB
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

# n<=32だから半分全列挙
def main():
    inf=1<<63
    n=II()
    ab=LLI(n)

    # AがBより何点多いかを前後半に分けて全列挙する
    def alldiff(si,ei):
        s=set()
        s.add(0)
        for a,b in ab[si:ei]:
            ns=set()
            for d in s:
                ns.add(d+a)
                ns.add(d-b)
            s=ns
        return list(sorted(s))

    pre=alldiff(0,n//2)
    pos=alldiff(n//2,n)
    #print(pre)
    #print(pos)

    # しゃくとり法で絶対値の最小値を探す
    # 前半(pre)の値一つに対して、後半(pos)の値2つと比較の必要がある
    # 前半の値がa=3で、pos=[-5,1,6]だったら、
    # -5(3と足して負になる),1(3と足して正になる)と比較する
    ans=inf
    j=len(pos)-1
    for i,a in enumerate(pre):
        while j>0 and a+pos[j]>=0:j-=1
        ans=min(ans,abs(a+pos[j]),abs(a+pos[j+1]))
    print(ans)

main()
0