#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int N = 2010;
const int M = 30010;
const int PW = 10;
const int oo = 2e9;
const int md = 998244353;
vector<int> g[N];
queue<int> q;
int n, m, k, mrk[M], used[N], tt = 0, lf, rt;
ll ans = 0;
bool dfs(int v){
if (used[v] == tt) return 0;
used[v] = tt;
for (int u : g[v])
if (u >= lf && u <= rt && (mrk[u] < 0 || dfs(mrk[u]))){
mrk[u] = v;
return 1;
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < k; i++){
int x, y;
cin >> x >> y;
x--; y--;
g[y].PB(x);
}
fill(mrk, mrk + n, -1);
for (int i = 0; i < m; i++)
q.push(i);
for (int l = 0, r = 0; l < n; l++){
while (r < n && sz(q)) {
tt++;
lf = l; rt = r;
while (sz(q)) {
int v = q.front();
if (dfs(v))
q.pop();
else break;
}
if (!sz(q)) break;
r++;
}
if (sz(q))
break;
ans += n - r;
if (mrk[l] >= 0){
q.push(mrk[l]);
mrk[l] = -1;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
41 ms |
632 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
508 KB |
Output is correct |
31 |
Correct |
274 ms |
1148 KB |
Output is correct |
32 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
121 ms |
1852 KB |
Output is correct |
36 |
Correct |
90 ms |
1528 KB |
Output is correct |
37 |
Correct |
831 ms |
1144 KB |
Output is correct |
38 |
Correct |
23 ms |
1656 KB |
Output is correct |
39 |
Correct |
103 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
632 KB |
Output is correct |
41 |
Correct |
8 ms |
888 KB |
Output is correct |
42 |
Correct |
9 ms |
888 KB |
Output is correct |
43 |
Correct |
13 ms |
1144 KB |
Output is correct |
44 |
Correct |
22 ms |
1884 KB |
Output is correct |
45 |
Correct |
11 ms |
1016 KB |
Output is correct |
46 |
Incorrect |
30 ms |
2168 KB |
Output isn't correct |
47 |
Correct |
26 ms |
2040 KB |
Output is correct |
48 |
Correct |
24 ms |
1912 KB |
Output is correct |
49 |
Correct |
35 ms |
2164 KB |
Output is correct |
50 |
Correct |
276 ms |
828 KB |
Output is correct |