結果

問題 No.771 しおり
ユーザー tobusakanatobusakana
提出日時 2022-10-23 16:00:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,091 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 134,136 KB
最終ジャッジ日時 2023-09-29 13:13:11
合計ジャッジ時間 15,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 999 ms
134,008 KB
testcase_01 AC 157 ms
84,044 KB
testcase_02 AC 58 ms
71,576 KB
testcase_03 AC 57 ms
71,332 KB
testcase_04 AC 56 ms
71,328 KB
testcase_05 AC 57 ms
71,340 KB
testcase_06 AC 56 ms
71,364 KB
testcase_07 AC 67 ms
71,520 KB
testcase_08 AC 76 ms
76,624 KB
testcase_09 AC 57 ms
71,460 KB
testcase_10 AC 56 ms
71,464 KB
testcase_11 AC 55 ms
71,440 KB
testcase_12 AC 56 ms
71,336 KB
testcase_13 AC 55 ms
71,592 KB
testcase_14 AC 72 ms
76,612 KB
testcase_15 AC 56 ms
71,512 KB
testcase_16 AC 58 ms
75,940 KB
testcase_17 AC 70 ms
76,548 KB
testcase_18 AC 54 ms
71,392 KB
testcase_19 AC 59 ms
75,848 KB
testcase_20 AC 57 ms
71,336 KB
testcase_21 AC 56 ms
71,632 KB
testcase_22 AC 60 ms
75,796 KB
testcase_23 AC 63 ms
76,580 KB
testcase_24 AC 69 ms
76,796 KB
testcase_25 AC 430 ms
105,040 KB
testcase_26 AC 84 ms
76,832 KB
testcase_27 AC 163 ms
84,064 KB
testcase_28 AC 293 ms
90,976 KB
testcase_29 AC 164 ms
83,932 KB
testcase_30 AC 1,042 ms
134,036 KB
testcase_31 AC 1,080 ms
133,736 KB
testcase_32 AC 88 ms
76,796 KB
testcase_33 AC 1,091 ms
134,128 KB
testcase_34 AC 1,066 ms
133,824 KB
testcase_35 AC 90 ms
76,708 KB
testcase_36 AC 81 ms
76,896 KB
testcase_37 AC 86 ms
77,916 KB
testcase_38 AC 92 ms
76,624 KB
testcase_39 AC 79 ms
76,652 KB
testcase_40 AC 410 ms
104,840 KB
testcase_41 AC 1,061 ms
133,732 KB
testcase_42 AC 1,040 ms
134,136 KB
testcase_43 AC 162 ms
83,784 KB
testcase_44 AC 1,037 ms
133,840 KB
testcase_45 AC 976 ms
134,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
N = int(readline())
A = [0] * N
B = [0] * N
for i in range(N):
  A[i], B[i] = map(int,readline().split())

# dp[S][v] = 並べた本の集合がSで、一番右にある本がvのときの醜さ

INF = 1 << 60
dp = [[INF] * N for i in range(1 << N)]

# まず最初の一冊を選ぶ
for i in range(N):
  dp[1 << i][i] = 0 # まだ醜さが定義されていない状態
  
for status in range(1, 1 << N): # 0の状態は考えない
  for v in range(N): # 最後の本
    if (status >> v) & 1 == 0:
      continue
    for target in range(N): # 次に置く本
      if (status >> target) & 1:
        continue # 既に置いてる
      # 本の厚さBi、表紙からの厚さAi
      # 今置かれている本に残っているしおりからの間隔はB[v] - A[v]
      # 次に置く本のしおりまでの間隔はA[target]
      gap = max(dp[status][v], B[v] - A[v] + A[target])
      next_status = status | (1 << target)
      if dp[next_status][target] > gap:
        dp[next_status][target] = gap

print(min(dp[-1]))
0