#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int n,m, k, ans, fMatch[maxn], iterNum[maxn], itV;
vector<vector<int> > gr;
bool dfs(int x, int& l, int& r){
if(iterNum[x] == itV){
return 0;
}
iterNum[x] = itV;
for(auto i : gr[x]){
if(i>=l and i <= r and (!fMatch[x] or dfs(fMatch[i], l, r)) ){
fMatch[i] = x;
return 1;
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> m >> k;
gr.resize(m+1, vector<int>());
for(int i = 0; i < k; ++i){
int a, b;
cin >> a >> b;
gr[b].push_back(a);
//gr[b].push_back(a);
}
int j = 1;
vector<int> notF;
for(int i = 1; i <= m; ++i){
notF.push_back(i);
}
for(int i = 1; i <= n; ++i){
while(j <= n){
if(!notF.size()){
break;
}
for(int j0 = notF.size()-1; j0 >= 0; --j0){
++itV;if(dfs(notF[j0], i, j)){
notF.pop_back();
} else {
break;
}
}
if(!notF.size()){
break;
}
++j;
//cerr << j << '\n';
}
if(notF.size()){
break;
}
//cerr << j << '\n';
ans += n-j;
if(fMatch[i]){
notF.push_back(fMatch[i]);
fMatch[i] = 0;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
496 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
31 |
Incorrect |
10 ms |
1004 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
35 |
Incorrect |
17 ms |
1644 KB |
Output isn't correct |
36 |
Incorrect |
18 ms |
1536 KB |
Output isn't correct |
37 |
Incorrect |
14 ms |
1144 KB |
Output isn't correct |
38 |
Incorrect |
22 ms |
1772 KB |
Output isn't correct |
39 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
40 |
Correct |
5 ms |
620 KB |
Output is correct |
41 |
Incorrect |
6 ms |
748 KB |
Output isn't correct |
42 |
Incorrect |
9 ms |
896 KB |
Output isn't correct |
43 |
Incorrect |
10 ms |
1132 KB |
Output isn't correct |
44 |
Incorrect |
23 ms |
1920 KB |
Output isn't correct |
45 |
Incorrect |
9 ms |
1004 KB |
Output isn't correct |
46 |
Incorrect |
27 ms |
2028 KB |
Output isn't correct |
47 |
Incorrect |
24 ms |
2028 KB |
Output isn't correct |
48 |
Incorrect |
26 ms |
1900 KB |
Output isn't correct |
49 |
Incorrect |
28 ms |
2028 KB |
Output isn't correct |
50 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |