結果
問題 | No.2263 Perms |
ユーザー | とりゐ |
提出日時 | 2023-04-04 17:03:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 213 ms / 2,000 ms |
コード長 | 3,751 bytes |
コンパイル時間 | 1,052 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 81,860 KB |
最終ジャッジ日時 | 2024-10-01 08:48:46 |
合計ジャッジ時間 | 7,487 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
55,304 KB |
testcase_01 | AC | 45 ms
55,772 KB |
testcase_02 | AC | 45 ms
55,600 KB |
testcase_03 | AC | 46 ms
56,464 KB |
testcase_04 | AC | 45 ms
54,808 KB |
testcase_05 | AC | 67 ms
69,192 KB |
testcase_06 | AC | 206 ms
80,480 KB |
testcase_07 | AC | 191 ms
79,452 KB |
testcase_08 | AC | 120 ms
78,008 KB |
testcase_09 | AC | 213 ms
81,860 KB |
testcase_10 | AC | 48 ms
61,660 KB |
testcase_11 | AC | 193 ms
79,780 KB |
testcase_12 | AC | 189 ms
79,492 KB |
testcase_13 | AC | 201 ms
80,832 KB |
testcase_14 | AC | 207 ms
81,144 KB |
testcase_15 | AC | 49 ms
61,224 KB |
testcase_16 | AC | 99 ms
76,740 KB |
testcase_17 | AC | 118 ms
76,796 KB |
testcase_18 | AC | 99 ms
76,712 KB |
testcase_19 | AC | 117 ms
77,004 KB |
testcase_20 | AC | 195 ms
80,224 KB |
testcase_21 | AC | 197 ms
80,196 KB |
testcase_22 | AC | 197 ms
80,276 KB |
testcase_23 | AC | 151 ms
77,952 KB |
testcase_24 | AC | 99 ms
77,228 KB |
testcase_25 | AC | 194 ms
79,700 KB |
testcase_26 | AC | 202 ms
80,568 KB |
testcase_27 | AC | 149 ms
78,544 KB |
testcase_28 | AC | 104 ms
76,996 KB |
testcase_29 | AC | 131 ms
77,732 KB |
testcase_30 | AC | 64 ms
67,124 KB |
testcase_31 | AC | 57 ms
65,464 KB |
testcase_32 | AC | 114 ms
77,244 KB |
testcase_33 | AC | 96 ms
76,780 KB |
testcase_34 | AC | 49 ms
56,772 KB |
testcase_35 | AC | 44 ms
54,664 KB |
testcase_36 | AC | 89 ms
77,140 KB |
testcase_37 | AC | 48 ms
57,308 KB |
testcase_38 | AC | 201 ms
81,196 KB |
testcase_39 | AC | 44 ms
55,076 KB |
testcase_40 | AC | 44 ms
56,056 KB |
ソースコード
from collections import deque class mf_graph: n=1 g=[[] for i in range(1)] pos=[] def __init__(self,N): self.n=N self.g=[[] for i in range(N)] self.pos=[] def add_edge(self,From,To,cap): assert 0<=From and From<self.n assert 0<=To and To<self.n assert 0<=cap m=len(self.pos) from_id=len(self.g[From]) self.pos.append([From,from_id]) to_id=len(self.g[To]) if From==To:to_id+=1 self.g[From].append([To,to_id,cap]) self.g[To].append([From,from_id,0]) return m def get_edge(self,i): m=len(self.pos) assert 0<=i and i<m _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e[0]][_e[1]] return [self.pos[i][0],_e[0],_e[2]+_re[2],_re[2]] def edges(self): m=len(self.pos) result=[] for i in range(m): a,b,c,d=self.get_edge(i) result.append((a,b,c,d)) return result def change_edge(self,i,new_cap,new_flow): m=len(self.pos) assert 0<=i and i<m assert 0<=new_flow and new_flow<=new_cap _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e[0]][_e[1]] _e[2]=new_cap-new_flow _re[2]=new_flow def flow(self,s,t,flow_limit=(1<<63)-1): assert 0<=s and s<self.n assert 0<=t and t<self.n assert s!=t def bfs(): level=[-1 for i in range(self.n)] level[s]=0 que=deque([]) que.append(s) while(que): v=que.popleft() for to,rev,cap in self.g[v]: if cap==0 or level[to]>=0:continue level[to]=level[v]+1 if to==t:return level que.append(to) return level def dfs(v,up): if (v==s):return up res=0 level_v=level[v] for i in range(Iter[v],len(self.g[v])): to,rev,cap=self.g[v][i] if (level_v<=level[to] or self.g[to][rev][2]==0):continue d=dfs(to,min(up-res,self.g[to][rev][2])) if d<=0:continue self.g[v][i][2]+=d self.g[to][rev][2]-=d res+=d if res==up:return res level[v]=self.n return res flow=0 while(flow<flow_limit): level=bfs() if level[t]==-1:break Iter=[0 for i in range(self.n)] f=dfs(t,flow_limit-flow) if not(f):break flow+=f return flow def min_cut(self,s): visited=[False for i in range(self.n)] que=deque([]) que.append(s) while(len(que)>0): p=que.popleft() visited[p]=True for to,rev,cap in self.g[p]: if cap and not(visited[to]): visited[to]=True que.append(to) return visited n,m=map(int,input().split()) a=[] for i in range(n): a.append(list(map(int,input().split()))) for i in range(n): sm=0 for j in range(n): sm+=a[i][j] if sm!=m: exit(print(-1)) for j in range(n): sm=0 for i in range(n): sm+=a[i][j] if sm!=m: exit(print(-1)) for _ in range(m): g=mf_graph(2*n+2) S=2*n T=2*n+1 for i in range(n): g.add_edge(S,i,1) g.add_edge(i+n,T,1) for j in range(n): if a[i][j]>0: g.add_edge(i,n+j,1) g.flow(S,T,n) p=[-1]*n for e in g.edges(): frm=e[0] to=e[1]-n flow=e[3] if 0<=frm<n and 0<=to<n and flow==1: p[frm]=to a[frm][to]-=1 assert sorted(p)==list(range(n)) print(*[i+1 for i in p])