結果

問題 No.1900 Don't be Powers of 2
ユーザー ShirotsumeShirotsume
提出日時 2022-04-08 23:51:35
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,016 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 292,464 KB
最終ジャッジ日時 2024-11-28 15:09:14
合計ジャッジ時間 28,539 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
54,656 KB
testcase_01 AC 47 ms
54,400 KB
testcase_02 AC 49 ms
60,160 KB
testcase_03 AC 737 ms
77,968 KB
testcase_04 AC 842 ms
77,552 KB
testcase_05 AC 750 ms
77,760 KB
testcase_06 AC 841 ms
77,584 KB
testcase_07 AC 754 ms
77,784 KB
testcase_08 AC 342 ms
79,228 KB
testcase_09 AC 214 ms
78,004 KB
testcase_10 AC 116 ms
77,032 KB
testcase_11 AC 156 ms
77,324 KB
testcase_12 AC 429 ms
80,412 KB
testcase_13 AC 77 ms
76,284 KB
testcase_14 AC 595 ms
77,248 KB
testcase_15 AC 79 ms
76,172 KB
testcase_16 AC 80 ms
76,504 KB
testcase_17 AC 692 ms
77,536 KB
testcase_18 AC 626 ms
77,568 KB
testcase_19 AC 842 ms
77,568 KB
testcase_20 AC 608 ms
77,288 KB
testcase_21 AC 504 ms
77,124 KB
testcase_22 AC 492 ms
77,208 KB
testcase_23 AC 802 ms
77,144 KB
testcase_24 AC 647 ms
77,312 KB
testcase_25 AC 641 ms
77,304 KB
testcase_26 TLE -
testcase_27 AC 735 ms
107,264 KB
testcase_28 AC 553 ms
81,884 KB
testcase_29 AC 525 ms
81,108 KB
testcase_30 AC 125 ms
77,288 KB
testcase_31 AC 45 ms
54,272 KB
testcase_32 AC 48 ms
54,528 KB
testcase_33 AC 1,849 ms
289,496 KB
testcase_34 AC 1,814 ms
289,340 KB
testcase_35 TLE -
testcase_36 AC 1,784 ms
264,232 KB
testcase_37 AC 660 ms
80,896 KB
testcase_38 AC 461 ms
131,932 KB
testcase_39 AC 300 ms
98,324 KB
testcase_40 AC 757 ms
78,532 KB
testcase_41 AC 734 ms
81,168 KB
testcase_42 AC 46 ms
54,400 KB
testcase_43 AC 46 ms
54,400 KB
testcase_44 AC 46 ms
54,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
 
class MaxFlow:
    inf = 10**18
 
    class E:
        def __init__(self,to,cap):
            self.to = to
            self.cap = cap
            self.rev = None
 
    def __init__(self,n):
        self.n = n
        self.graph = [[] for _ in range(n)]
 
    def add_edge(self, fr, to, cap):
        graph = self.graph
        edge = self.E(to,cap)
        edge2 = self.E(fr,0)
        edge.rev = edge2
        edge2.rev = edge
        graph[fr].append(edge)
        graph[to].append(edge2)
 
    def bfs(self, s, t):
        level = self.level = [self.n]*self.n
        q = deque([s])
        level[s] = 0
        while q:
            now = q.popleft()
            lw = level[now]+1
            for e in self.graph[now]:
                if e.cap and level[e.to]> lw:
                    level[e.to] = lw
                    if e.to == t:
                        return True
                    q.append(e.to)
        return False
 
    def dfs(self, s, t, up):
        graph = self.graph
        it = self.it
        level = self.level
 
        st = deque([t])
        while st:
            v = st[-1]
            if v == s:
                st.pop()
                flow = up
                for w in st:
                    e = graph[w][it[w]].rev
                    flow = min(flow, e.cap)
                for w in st:
                    e = graph[w][it[w]]
                    e.cap += flow
                    e.rev.cap -= flow
                return flow
            lv = level[v]-1
            while it[v] < len(graph[v]):
                e = graph[v][it[v]]
                re = e.rev
                if re.cap == 0 or lv != level[e.to]:
                    it[v] += 1
                    continue
                st.append(e.to)
                break
            if it[v] == len(graph[v]):
                st.pop()
                level[v] = self.n
 
        return 0
 
    def flow(self,s,t,flow_limit=inf):
        flow = 0
        while flow < flow_limit and self.bfs(s,t):
            self.it = [0]*self.n
            while flow < flow_limit:
                f = self.dfs(s,t,flow_limit-flow)
                if f == 0:
                    break
                flow += f
        return flow
 
    def min_cut(self,s):
        visited = [0]*self.n
        q = deque([s])
        while q:
            v = q.pop()
            visited[v] = 1
            for e in self.graph[v]:
                if e.cap and not visited[e.to]:
                    q.append(e.to)
        return visited

def popcount(m):
    cnt = 0
    for i in range(30):
        if 1 & (m >> i):
            cnt += 1
    return cnt
n=int(input())
a=list(map(int,input().split()))

s,t=n,n+1
g=MaxFlow(n+2)
inf=1

for i in range(n):
  if popcount(a[i])%2==0:
    g.add_edge(s,i,1)
  else:
    g.add_edge(i,t,1)

for i in range(n):
  for j in range(i+1,n):
    if popcount(a[i]^a[j])==1:
      if popcount(a[i])%2==0:
        g.add_edge(i,j,inf)
      else:
        g.add_edge(j,i,inf)
print(n-g.flow(s,t))
0