結果

問題 No.241 出席番号(1)
ユーザー roarisroaris
提出日時 2019-12-06 11:24:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 78,216 KB
最終ジャッジ日時 2023-08-24 19:48:23
合計ジャッジ時間 5,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,744 KB
testcase_01 AC 104 ms
76,988 KB
testcase_02 AC 111 ms
76,972 KB
testcase_03 AC 93 ms
71,632 KB
testcase_04 AC 106 ms
76,940 KB
testcase_05 AC 91 ms
71,804 KB
testcase_06 AC 94 ms
71,792 KB
testcase_07 AC 93 ms
71,536 KB
testcase_08 AC 92 ms
71,608 KB
testcase_09 AC 92 ms
71,640 KB
testcase_10 AC 94 ms
71,532 KB
testcase_11 AC 93 ms
71,816 KB
testcase_12 AC 92 ms
71,376 KB
testcase_13 AC 101 ms
76,644 KB
testcase_14 AC 115 ms
77,440 KB
testcase_15 AC 111 ms
77,440 KB
testcase_16 AC 96 ms
71,532 KB
testcase_17 AC 96 ms
71,636 KB
testcase_18 AC 92 ms
71,876 KB
testcase_19 AC 91 ms
71,868 KB
testcase_20 AC 93 ms
71,620 KB
testcase_21 AC 94 ms
71,660 KB
testcase_22 AC 91 ms
71,880 KB
testcase_23 AC 111 ms
77,536 KB
testcase_24 AC 113 ms
77,540 KB
testcase_25 AC 117 ms
78,216 KB
testcase_26 AC 115 ms
77,612 KB
testcase_27 AC 111 ms
77,480 KB
testcase_28 AC 112 ms
77,512 KB
testcase_29 AC 116 ms
77,608 KB
testcase_30 AC 114 ms
77,544 KB
testcase_31 AC 115 ms
77,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

def dfs(v, t, f, used):
    if v==t:
        return f
    
    used[v] = True
    
    for nv, cap in edges[v].items():
        if not used[nv] and cap>0:
            d = dfs(nv, t, min(f, cap), used)
            
            if d>0:
                edges[v][nv] -= d
                edges[nv][v] += d
                
                return d
    
    return 0

def max_flow(s, t):
    flow = 0
    
    while True:
        used = [False]*(2*N+2)
        f = dfs(s, t, 10**18, used)
        
        if f==0:
            return flow
        
        flow += f
        
N = int(input())
A = [int(input()) for _ in range(N)]
edges = defaultdict(dict)

for i in range(1, N+1):
    edges[0][i] = 1
    edges[i][0] = 0

for i in range(1, N+1):
    for j in range(N+1, 2*N+1):
        if j!=A[i-1]+N+1:
            edges[i][j] = 1
            edges[j][i] = 0

for i in range(N+1, 2*N+1):
    edges[i][2*N+1] = 1
    edges[2*N+1][i] = 0

f = max_flow(0, 2*N+1)

if f<N:
    print(-1)
    exit()

for i in range(1, N+1):
    for j in range(N+1, 2*N+1):
        if j in edges[i] and edges[i][j]==0:
            print(j-N-1)
            break
0