# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
341253 | 2020-12-29T10:13:37 Z | juggernaut | 결혼 문제 (IZhO14_marriage) | C++14 | 455 ms | 2028 KB |
#include<bits/stdc++.h> using namespace std; int n,m,qq,mt[30005],GL,GR,vis[2005],timer; vector<int>g[2005]; queue<int>q; bool kuhn(int v){ if(vis[v]==timer)return false; vis[v]=timer; for(int to:g[v]){ if(to<GL||to>GR)continue; if(!mt[to]||kuhn(mt[to])){ mt[to]=v; return true; } } return false; } bool check(){ while(!q.empty()){ int v=q.front(); q.pop(); timer++; if(!kuhn(v)){ q.push(v); return false; } } return true; } int main(){ scanf("%d%d%d",&n,&m,&qq); while(qq--){ int x,y; scanf("%d%d",&x,&y); g[y].push_back(x); } for(int i=1;i<=m;i++)sort(g[i].begin(),g[i].end()); for(int i=1;i<=m;i++)q.push(i); int ans=0; GR=1; for(GL=1;GL<=n;GL++){ while(GR<=n&&!check())GR++; ans+=n-GR+1; if(mt[GL]){ q.push(mt[GL]); mt[GL]=0; } } cout<<ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 3 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 492 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 19 ms | 492 KB | Output is correct |
26 | Correct | 4 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 KB | Output is correct |
29 | Correct | 3 ms | 492 KB | Output is correct |
30 | Correct | 2 ms | 492 KB | Output is correct |
31 | Correct | 157 ms | 1004 KB | Output is correct |
32 | Correct | 9 ms | 492 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 3 ms | 364 KB | Output is correct |
35 | Correct | 130 ms | 1644 KB | Output is correct |
36 | Correct | 92 ms | 1516 KB | Output is correct |
37 | Correct | 455 ms | 1260 KB | Output is correct |
38 | Correct | 21 ms | 1644 KB | Output is correct |
39 | Correct | 71 ms | 748 KB | Output is correct |
40 | Correct | 4 ms | 620 KB | Output is correct |
41 | Correct | 9 ms | 748 KB | Output is correct |
42 | Correct | 8 ms | 876 KB | Output is correct |
43 | Correct | 11 ms | 1132 KB | Output is correct |
44 | Correct | 20 ms | 1772 KB | Output is correct |
45 | Correct | 11 ms | 1004 KB | Output is correct |
46 | Correct | 218 ms | 2028 KB | Output is correct |
47 | Correct | 23 ms | 1772 KB | Output is correct |
48 | Correct | 21 ms | 1772 KB | Output is correct |
49 | Correct | 329 ms | 2028 KB | Output is correct |
50 | Correct | 175 ms | 748 KB | Output is correct |