結果

問題 No.1900 Don't be Powers of 2
ユーザー chineristACchineristAC
提出日時 2022-04-08 21:38:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,353 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 333,504 KB
最終ジャッジ日時 2024-11-28 12:15:52
合計ジャッジ時間 13,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
56,780 KB
testcase_01 AC 49 ms
56,392 KB
testcase_02 AC 50 ms
57,036 KB
testcase_03 AC 175 ms
78,672 KB
testcase_04 AC 186 ms
78,372 KB
testcase_05 AC 175 ms
78,604 KB
testcase_06 AC 172 ms
78,540 KB
testcase_07 AC 180 ms
78,360 KB
testcase_08 AC 149 ms
80,016 KB
testcase_09 AC 117 ms
78,516 KB
testcase_10 AC 92 ms
78,084 KB
testcase_11 AC 105 ms
78,204 KB
testcase_12 AC 171 ms
80,672 KB
testcase_13 AC 55 ms
65,708 KB
testcase_14 AC 145 ms
78,464 KB
testcase_15 AC 55 ms
65,792 KB
testcase_16 AC 54 ms
64,824 KB
testcase_17 AC 165 ms
78,464 KB
testcase_18 AC 152 ms
78,472 KB
testcase_19 AC 171 ms
78,472 KB
testcase_20 AC 146 ms
78,500 KB
testcase_21 AC 141 ms
78,540 KB
testcase_22 AC 138 ms
78,752 KB
testcase_23 AC 156 ms
73,924 KB
testcase_24 AC 167 ms
74,464 KB
testcase_25 AC 166 ms
74,408 KB
testcase_26 AC 1,353 ms
332,676 KB
testcase_27 AC 345 ms
107,516 KB
testcase_28 AC 198 ms
81,660 KB
testcase_29 AC 184 ms
81,124 KB
testcase_30 AC 91 ms
78,064 KB
testcase_31 AC 47 ms
58,204 KB
testcase_32 AC 46 ms
56,404 KB
testcase_33 AC 1,242 ms
333,492 KB
testcase_34 AC 1,246 ms
333,504 KB
testcase_35 AC 1,337 ms
333,432 KB
testcase_36 AC 1,071 ms
272,800 KB
testcase_37 AC 224 ms
81,012 KB
testcase_38 AC 362 ms
131,200 KB
testcase_39 AC 208 ms
98,948 KB
testcase_40 AC 225 ms
79,852 KB
testcase_41 AC 248 ms
82,348 KB
testcase_42 AC 46 ms
56,604 KB
testcase_43 AC 46 ms
56,836 KB
testcase_44 AC 46 ms
57,896 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

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

S = set([1<<i for i in range(31)])

N = int(input())
A = li()

G = Dinic(N+2)
for i in range(N):
    if bin(A[i]).count("1")&1:
        G.add_edge(N,i,1)
    else:
        G.add_edge(i,N+1,1)

for i in range(N):
    t = bin(A[i]).count("1")
    for j in range(N):
        if A[i]^A[j] in S:
            if t&1:
                G.add_edge(i,j,1)

F = G.flow(N,N+1)
print(N-F)
0