結果

問題 No.1900 Don't be Powers of 2
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-04-09 00:22:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,438 ms / 2,000 ms
コード長 2,081 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 330,156 KB
最終ジャッジ日時 2023-08-19 02:52:24
合計ジャッジ時間 14,755 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,672 KB
testcase_01 AC 80 ms
71,444 KB
testcase_02 AC 78 ms
71,724 KB
testcase_03 AC 160 ms
78,640 KB
testcase_04 AC 149 ms
78,820 KB
testcase_05 AC 155 ms
78,812 KB
testcase_06 AC 145 ms
78,696 KB
testcase_07 AC 140 ms
78,676 KB
testcase_08 AC 158 ms
80,528 KB
testcase_09 AC 136 ms
79,648 KB
testcase_10 AC 106 ms
77,980 KB
testcase_11 AC 122 ms
78,464 KB
testcase_12 AC 179 ms
82,036 KB
testcase_13 AC 88 ms
77,296 KB
testcase_14 AC 134 ms
78,132 KB
testcase_15 AC 94 ms
77,596 KB
testcase_16 AC 89 ms
77,444 KB
testcase_17 AC 139 ms
78,660 KB
testcase_18 AC 133 ms
78,224 KB
testcase_19 AC 148 ms
78,824 KB
testcase_20 AC 127 ms
78,284 KB
testcase_21 AC 122 ms
78,092 KB
testcase_22 AC 125 ms
78,060 KB
testcase_23 AC 125 ms
78,092 KB
testcase_24 AC 129 ms
77,896 KB
testcase_25 AC 139 ms
78,176 KB
testcase_26 AC 1,438 ms
330,156 KB
testcase_27 AC 355 ms
109,720 KB
testcase_28 AC 179 ms
82,920 KB
testcase_29 AC 178 ms
82,808 KB
testcase_30 AC 115 ms
78,576 KB
testcase_31 AC 76 ms
71,608 KB
testcase_32 AC 78 ms
71,536 KB
testcase_33 AC 1,369 ms
323,460 KB
testcase_34 AC 1,366 ms
323,432 KB
testcase_35 AC 1,401 ms
325,048 KB
testcase_36 AC 1,163 ms
286,116 KB
testcase_37 AC 188 ms
82,444 KB
testcase_38 AC 328 ms
135,180 KB
testcase_39 AC 193 ms
97,736 KB
testcase_40 AC 186 ms
80,408 KB
testcase_41 AC 221 ms
83,160 KB
testcase_42 AC 79 ms
71,648 KB
testcase_43 AC 78 ms
71,612 KB
testcase_44 AC 78 ms
71,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow



def bc(x):
    res=0
    for i in range(30):
        res+=(x>>i)&1
    return res%2
n=int(input())
a=[0]+list(map(int,input().split()))
ng=set()
for i in range(30):
    ng.add(2**i)

g=Dinic(n+3)
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if not a[i]^a[j] in ng:continue
        if bc(a[i])==0:g.add_edge(i,j,1)
        else:g.add_edge(j,i,1)

for i in range(1,n+1):
    if bc(a[i])==0:
        g.add_edge(0,i,1)
    else:
        g.add_edge(i,n+1,1)
ans=g.flow(0,n+1)
print(n-ans)




0