結果

問題 No.1900 Don't be Powers of 2
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-08 23:41:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,407 ms / 2,000 ms
コード長 2,878 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 286,776 KB
最終ジャッジ日時 2023-08-19 02:14:02
合計ジャッジ時間 35,405 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,792 KB
testcase_01 AC 86 ms
71,492 KB
testcase_02 AC 87 ms
71,776 KB
testcase_03 AC 1,360 ms
79,036 KB
testcase_04 AC 1,389 ms
79,528 KB
testcase_05 AC 1,283 ms
79,072 KB
testcase_06 AC 1,356 ms
79,324 KB
testcase_07 AC 1,371 ms
79,112 KB
testcase_08 AC 412 ms
80,600 KB
testcase_09 AC 271 ms
78,996 KB
testcase_10 AC 155 ms
78,024 KB
testcase_11 AC 191 ms
78,372 KB
testcase_12 AC 534 ms
82,132 KB
testcase_13 AC 107 ms
77,036 KB
testcase_14 AC 988 ms
78,928 KB
testcase_15 AC 113 ms
77,384 KB
testcase_16 AC 111 ms
77,416 KB
testcase_17 AC 1,288 ms
79,200 KB
testcase_18 AC 938 ms
78,908 KB
testcase_19 AC 1,407 ms
79,172 KB
testcase_20 AC 962 ms
79,616 KB
testcase_21 AC 914 ms
79,316 KB
testcase_22 AC 857 ms
78,804 KB
testcase_23 AC 680 ms
79,208 KB
testcase_24 AC 1,061 ms
79,180 KB
testcase_25 AC 721 ms
79,220 KB
testcase_26 AC 1,311 ms
286,776 KB
testcase_27 AC 817 ms
108,336 KB
testcase_28 AC 726 ms
83,300 KB
testcase_29 AC 652 ms
82,512 KB
testcase_30 AC 146 ms
77,956 KB
testcase_31 AC 86 ms
71,768 KB
testcase_32 AC 86 ms
71,544 KB
testcase_33 AC 1,180 ms
286,216 KB
testcase_34 AC 1,193 ms
286,232 KB
testcase_35 AC 1,322 ms
286,776 KB
testcase_36 AC 1,048 ms
262,028 KB
testcase_37 AC 905 ms
82,504 KB
testcase_38 AC 638 ms
133,100 KB
testcase_39 AC 586 ms
101,492 KB
testcase_40 AC 1,375 ms
80,844 KB
testcase_41 AC 1,325 ms
83,188 KB
testcase_42 AC 88 ms
71,584 KB
testcase_43 AC 88 ms
71,568 KB
testcase_44 AC 87 ms
71,720 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


n = int(input())
A = list(map(int,input().split()))
s = n
t = n+1
mf = MaxFlow(t+1)

for i in range(n):
    if bin(A[i]).count("1")%2 == 0:
        mf.add_edge(i,t,1)
        continue

    mf.add_edge(s,i,1)
    a = A[i]
    for j in range(n):
        if bin(a^A[j]).count("1") == 1:
            mf.add_edge(i,j,1)
        

ans = n - mf.flow(s,t)
print(ans)
0