Skip to content

Commit

Permalink
ABC041 D問題 高速化(5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus-MK committed Oct 27, 2020
1 parent 939eba3 commit 87ccd0a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ABC_001-075/abc041d.py
Expand Up @@ -10,8 +10,8 @@
# PyPy3だと通る(マジかよ)
# 計算量は外側のループから順に、2**n * (n + m)
# 2**16 * (16 + (16*15)/ 2) = 8912896
# PyPy3 230ms
# Python TLE(この問題は制約3sec)
# PyPy3 169ms
# Python 1626ms(この問題は制約3sec)

import sys
input = sys.stdin.readline
Expand All @@ -27,13 +27,13 @@
may_be_first = [True] * n
for pair in condition:
# S-v がfitst, vがsecondとなる対があるか
if (2**pair[0] & idx) and (2**pair[1] & idx):
if (1<<pair[0] & idx) and (1<<pair[1] & idx):
may_be_first[pair[1]] = False

for digit in range(n):
if 2**digit & idx: # digitに対応する頂点vが、今考えている頂点集合Sに含まれていて
if 1<<digit & idx: # digitに対応する頂点vが、今考えている頂点集合Sに含まれていて
if may_be_first[digit]:
dp[idx] += dp[idx - 2**digit]
dp[idx] += dp[idx - (1<<digit)]

print(dp[-1])
# print(dp)

0 comments on commit 87ccd0a

Please sign in to comment.