結果

問題 No.771 しおり
ユーザー mkawa2mkawa2
提出日時 2022-03-08 16:21:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,981 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 113,940 KB
最終ジャッジ日時 2023-09-30 22:35:54
合計ジャッジ時間 27,514 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,831 ms
113,616 KB
testcase_01 AC 269 ms
80,804 KB
testcase_02 AC 77 ms
71,344 KB
testcase_03 AC 78 ms
71,240 KB
testcase_04 AC 77 ms
71,240 KB
testcase_05 AC 76 ms
71,092 KB
testcase_06 AC 72 ms
71,412 KB
testcase_07 AC 76 ms
71,368 KB
testcase_08 AC 97 ms
75,960 KB
testcase_09 AC 76 ms
71,108 KB
testcase_10 AC 76 ms
71,416 KB
testcase_11 AC 76 ms
71,396 KB
testcase_12 AC 74 ms
71,272 KB
testcase_13 AC 76 ms
71,352 KB
testcase_14 AC 100 ms
76,832 KB
testcase_15 AC 75 ms
71,208 KB
testcase_16 AC 82 ms
75,568 KB
testcase_17 AC 93 ms
76,108 KB
testcase_18 AC 76 ms
71,516 KB
testcase_19 AC 82 ms
75,844 KB
testcase_20 AC 74 ms
70,976 KB
testcase_21 AC 75 ms
71,452 KB
testcase_22 AC 82 ms
75,456 KB
testcase_23 AC 90 ms
76,172 KB
testcase_24 AC 94 ms
76,128 KB
testcase_25 AC 929 ms
93,916 KB
testcase_26 AC 114 ms
77,104 KB
testcase_27 AC 267 ms
80,612 KB
testcase_28 AC 636 ms
85,124 KB
testcase_29 AC 271 ms
80,616 KB
testcase_30 AC 1,890 ms
113,936 KB
testcase_31 AC 1,981 ms
113,940 KB
testcase_32 AC 143 ms
77,396 KB
testcase_33 AC 1,927 ms
113,660 KB
testcase_34 AC 1,890 ms
113,620 KB
testcase_35 AC 148 ms
77,512 KB
testcase_36 AC 109 ms
76,672 KB
testcase_37 AC 110 ms
76,808 KB
testcase_38 AC 143 ms
77,460 KB
testcase_39 AC 106 ms
76,840 KB
testcase_40 AC 890 ms
94,484 KB
testcase_41 AC 1,949 ms
113,588 KB
testcase_42 AC 1,848 ms
113,768 KB
testcase_43 AC 271 ms
80,600 KB
testcase_44 AC 1,932 ms
113,392 KB
testcase_45 AC 1,824 ms
113,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

def main():
    n = II()
    ab = LLI(n)

    dp = [inf]*n*(1 << n)
    for i in range(n): dp[(1 << i)*n+i] = 0

    ans = inf
    for s in range(1, 1 << n):
        for i, (ai, bi) in enumerate(ab):
            pre = dp[s*n+i]
            for j, (aj, bj) in enumerate(ab):
                if s >> j & 1: continue
                ns = s | 1 << j
                nv = bi-ai+aj
                if pre > nv: nv = pre
                if ns+1 == 1 << n:
                    if nv < ans: ans = nv
                else:
                    if nv < dp[ns*n+j]: dp[ns*n+j] = nv

    print(ans)

main()
0