結果

問題 No.1900 Don't be Powers of 2
ユーザー ShirotsumeShirotsume
提出日時 2022-02-14 00:38:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 7,025 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 79,336 KB
最終ジャッジ日時 2023-09-25 14:07:52
合計ジャッジ時間 8,390 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 76 ms
75,660 KB
testcase_32 AC 80 ms
75,588 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 73 ms
71,336 KB
testcase_43 AC 73 ms
71,288 KB
testcase_44 AC 73 ms
71,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class maxflow:
    """It solves maximum flow problem.
    """
 
    def __init__(self, n):
        """It creates a graph of n vertices and 0 edges.
 
        Constraints
        -----------
 
        >   0 <= n <= 10 ** 8
 
        Complexity
        ----------
 
        >   O(n)
        """
        self.n = n
        self.g = [[] for _ in range(self.n)]
        self.pos = []
 
    def add_edge(self, from_, to, capacity):
        cap=capacity
        """It adds an edge oriented from the vertex `from_` to the vertex `to` 
        with the capacity `cap` and the flow amount 0. 
        It returns an integer k such that this is the k-th edge that is added.
 
        Constraints
        -----------
 
        >   0 <= from_, to < n
 
        >   0 <= cap
 
        Complexity
        ----------
 
        >   O(1) amortized
        """
        # assert 0 <= from_ < self.n
        # assert 0 <= to < self.n
        # assert 0 <= cap
        m = len(self.pos)
        self.pos.append((from_, len(self.g[from_])))
        self.g[from_].append(self.__class__._edge(to, len(self.g[to]), cap))
        self.g[to].append(self.__class__._edge(
            from_, len(self.g[from_]) - 1, 0))
        return m
 
    class edge:
        def __init__(self, from_, to, cap, flow):
            self.from_ = from_
            self.to = to
            self.cap = cap
            self.flow = flow
 
    def get_edge(self, i):
        """It returns the current internal state of the edges.
        The edges are ordered in the same order as added by add_edge.
 
        Complexity
        ----------
 
        > O(1)
        """
        # assert 0 <= i < len(self.pos)
        _e = self.g[self.pos[i][0]][self.pos[i][1]]
        _re = self.g[_e.to][_e.rev]
        return self.__class__.edge(self.pos[i][0], _e.to, _e.cap + _re.cap, _re.cap)
 
    def edges(self):
        """It returns the current internal state of the edges.
        The edges are ordered in the same order as added by add_edge.
 
        Complexity
        ----------
 
        >   O(m), where m is the number of added edges.
        """
        result = []
        for i in range(len(self.pos)):
            _e = self.g[self.pos[i][0]][self.pos[i][1]]
            _re = self.g[_e.to][_e.rev]
            result.append(self.__class__.edge(
                self.pos[i][0], _e.to, _e.cap + _re.cap, _re.cap))
        return result
 
    def change_edge(self, i, new_cap, new_flow):
        """It changes the capacity and the flow amount of the ii-th edge to new_cap and new_flow, respectively. It doesn't change the capacity or the flow amount of other edges. See Appendix for further details.
 
        Constraints
        -----------
 
        >   0 <= newflow <= newcap
 
        Complexity
        ----------
 
        >   O(1)
        """
        # assert 0 <= i < len(self.pos)
        # assert 0 <= new_flow <= new_cap
        _e = self.g[self.pos[i][0]][self.pos[i][1]]
        _re = self.g[_e.to][_e.rev]
        _e.cap = new_cap - new_flow
        _re.cap = new_flow
 
    def _bfs(self, s, t):
        self.level = [-1] * self.n
        self.level[s] = 0
        q = [s]
        while q:
            nq = []
            for v in q:
                for e in self.g[v]:
                    if e.cap and self.level[e.to] == -1:
                        self.level[e.to] = self.level[v] + 1
                        if e.to == t:
                            return True
                        nq.append(e.to)
            q = nq
        return False
 
    def _dfs(self, s, t, up):
        st = [t]
        while st:
            v = st[-1]
            if v == s:
                st.pop()
                flow = up
                for w in st:
                    e = self.g[w][self.it[w]]
                    flow = min(flow, self.g[e.to][e.rev].cap)
                for w in st:
                    e = self.g[w][self.it[w]]
                    e.cap += flow
                    self.g[e.to][e.rev].cap -= flow
                return flow
            while self.it[v] < len(self.g[v]):
                e = self.g[v][self.it[v]]
                w = e.to
                cap = self.g[e.to][e.rev].cap
                if cap and self.level[v] > self.level[w]:
                    st.append(w)
                    break
                self.it[v] += 1
            else:
                st.pop()
                self.level[v] = self.n
        return 0
 
    def flow(self, s, t, flow_limit=float('inf')):
        """It augments the flow from s to t as much as possible. 
        It returns the amount of the flow augmented.
        You may call it multiple times. 
        See Appendix in the document of AC Library for further details.
 
        Constraints
        -----------
 
        >   s != t
 
        Complexity
        ----------
 
        >   O(min(n^(2/3)m, m^(3/2))) (if all the capacities are 1) or
 
        >   O(n^2 m) (general),
 
        where m is the number of added edges.
        """
        # assert 0 <= s < self.n
        # assert 0 <= t < self.n
        # assert s != t
        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 not f:
                    break
                flow += f
        return flow
 
    def min_cut(self, s):
        """It returns a vector of length n, 
        such that the i-th element is true if and only if there is a directed path from s to i in the residual network. 
        The returned vector corresponds to a s−t minimum cut after calling flow(s, t) exactly once without flow_limit. 
        See Appendix in the document of AC Library for further details.
 
        Complexity
        ----------
 
        >   O(n + m), where m is the number of added edges.
        """
        visited = [False] * self.n
        q = [s]
        while q:
            nq = []
            for p in q:
                visited[p] = True
                for e in self.g[p]:
                    if e.cap and not visited[e.to]:
                        nq.append(e.to)
            q = nq
        return visited
 
    class _edge:
        def __init__(self, to, rev, cap):
            self.to = to
            self.rev = rev
            self.cap = cap
 
 

def isSquare(x):
    #xは平方数か?
    ng = 3 * 10 ** 9 + 1
    ok = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid * mid <= x:
            ok = mid
        else:
            ng = mid
    if ok * ok == x:
        return True
    else:
        return False
    
N = int(input())

A = list(map(int,input().split()))

if N > 20:
    raise Exception
ans = 0
for i in range(2 ** N):
    b = []
    for j in range(N):
        if 1 & (i >> j):
            b.append(A[j])
    l = len(b)
    flag = True
    for x in range(l):
        for y in range(l):
            if isSquare(b[x] ** 2 + b[y] ** 2):
                flag = False
    if flag:
        ans = max(ans, len(b))
print(ans)


0