結果
問題 | No.241 出席番号(1) |
ユーザー | Mao-beta |
提出日時 | 2020-09-25 23:26:35 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 2,480 bytes |
コンパイル時間 | 104 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-06-28 08:08:59 |
合計ジャッジ時間 | 2,591 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,008 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 34 ms
11,264 KB |
testcase_03 | AC | 33 ms
11,008 KB |
testcase_04 | AC | 33 ms
11,136 KB |
testcase_05 | AC | 31 ms
11,136 KB |
testcase_06 | AC | 30 ms
11,008 KB |
testcase_07 | AC | 31 ms
11,136 KB |
testcase_08 | AC | 31 ms
11,008 KB |
testcase_09 | AC | 31 ms
11,136 KB |
testcase_10 | AC | 31 ms
11,008 KB |
testcase_11 | AC | 31 ms
11,008 KB |
testcase_12 | AC | 31 ms
11,008 KB |
testcase_13 | AC | 32 ms
11,008 KB |
testcase_14 | AC | 34 ms
11,392 KB |
testcase_15 | AC | 34 ms
11,392 KB |
testcase_16 | AC | 31 ms
11,008 KB |
testcase_17 | AC | 31 ms
11,008 KB |
testcase_18 | AC | 31 ms
11,008 KB |
testcase_19 | AC | 30 ms
11,136 KB |
testcase_20 | AC | 30 ms
11,008 KB |
testcase_21 | AC | 31 ms
11,136 KB |
testcase_22 | AC | 31 ms
11,008 KB |
testcase_23 | AC | 33 ms
11,392 KB |
testcase_24 | AC | 35 ms
11,648 KB |
testcase_25 | AC | 35 ms
11,520 KB |
testcase_26 | AC | 36 ms
11,520 KB |
testcase_27 | AC | 35 ms
11,520 KB |
testcase_28 | AC | 35 ms
11,520 KB |
testcase_29 | AC | 34 ms
11,648 KB |
testcase_30 | AC | 35 ms
11,648 KB |
testcase_31 | AC | 36 ms
11,648 KB |
ソースコード
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() INF = 10 ** 20 class Dinic: """ 最大流(Dinic) """ def __init__(self, n): self.n = n self.links = [[] for _ in range(n)] self.depth = None self.progress = None def add_link(self, _from, to, cap): self.links[_from].append([cap, to, len(self.links[to])]) self.links[to].append([0, _from, len(self.links[_from]) - 1]) def bfs(self, s): from collections import deque depth = [-1] * self.n depth[s] = 0 q = deque([s]) while q: v = q.popleft() for cap, to, rev in self.links[v]: if cap > 0 and depth[to] < 0: depth[to] = depth[v] + 1 q.append(to) self.depth = depth def dfs(self, v, t, flow): if v == t: return flow links_v = self.links[v] for i in range(self.progress[v], len(links_v)): self.progress[v] = i cap, to, rev = link = links_v[i] if cap == 0 or self.depth[v] >= self.depth[to]: continue d = self.dfs(to, t, min(flow, cap)) if d == 0: continue link[0] -= d self.links[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.depth[t] < 0: return flow self.progress = [0] * self.n current_flow = self.dfs(s, t, INF) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, INF) def main(): N = NI() A = [NI() for _ in range(N)] s, t = 2*N, 2*N+1 din = Dinic(2*N+2) for i in range(N): din.add_link(s, i, 1) din.add_link(i+N, t, 1) hate = A[i] for j in range(N): if j == hate: continue din.add_link(i, j+N, 1) if din.max_flow(s, t) != N: print(-1) exit() for i in range(N): for cap, to, _ in din.links[i]: if cap == 0: print(to - N) if __name__ == "__main__": main()