/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define ld long double
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)3e4 + 7; // make sure this is right
const int M = (int)2e3 + 7;
const int inf = (int)2e9 + 7;
const ll INF = (ll)3e18 + 7;
const double PI = acos(-1);
ll MOD = (ll)1e9 + 7; // make sure this is right
bool bit(int x, int i) {
return x >> i & 1;
}
int sum(int x, int y) {
x += y;
if(x >= MOD) x -= MOD;
return x;
}
pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n, m, k, mt[N + M];
int T, used[N], a[4 * N], b[4 * N];
vector<int> g[N], pos[N];
bool dfs(int v) {
if(used[v] == T) return 0;
used[v] = T;
for(auto to : g[v]) {
if(mt[to] == -1) {
mt[to] = v;
return 1;
}
}
for(auto to : g[v]) {
if(dfs(mt[to])) {
mt[to] = v;
return 1;
}
}
return 0;
}
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= k; ++i) {
cin >> a[i] >> b[i];
pos[a[i]].pb(b[i]);
}
int ans = 0;
for(int l = 1; l <= n; ++l) {
for(int i = 1; i <= n; ++i) g[i].clear();
for(int r = l; r <= n; ++r) {
for(int i = n + 1; i <= n + m; ++i) mt[i] = -1;
for(auto x : pos[r]) {
g[r].pb(x + n);
}
for(int i = 1; i <= n; ++i) {
T++;
dfs(i);
}
bool ok = 1;
for(int i = n + 1; i <= n + m && ok; ++i) ok &= (mt[i] != -1);
if(ok) ans++;
}
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("g.in", "r", stdin);
// freopen("g.out", "w", stdout);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1620 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
1 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1620 KB |
Output is correct |
14 |
Correct |
1 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
1748 KB |
Output is correct |
16 |
Correct |
1 ms |
1748 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1620 KB |
Output is correct |
19 |
Correct |
117 ms |
1792 KB |
Output is correct |
20 |
Correct |
38 ms |
1748 KB |
Output is correct |
21 |
Correct |
5 ms |
1752 KB |
Output is correct |
22 |
Correct |
4 ms |
1748 KB |
Output is correct |
23 |
Correct |
27 ms |
1748 KB |
Output is correct |
24 |
Correct |
17 ms |
1764 KB |
Output is correct |
25 |
Execution timed out |
1581 ms |
1944 KB |
Time limit exceeded |
26 |
Execution timed out |
1589 ms |
1792 KB |
Time limit exceeded |
27 |
Correct |
506 ms |
1756 KB |
Output is correct |
28 |
Correct |
299 ms |
1748 KB |
Output is correct |
29 |
Execution timed out |
1587 ms |
1920 KB |
Time limit exceeded |
30 |
Execution timed out |
1588 ms |
1896 KB |
Time limit exceeded |
31 |
Execution timed out |
1588 ms |
2608 KB |
Time limit exceeded |
32 |
Execution timed out |
1588 ms |
1996 KB |
Time limit exceeded |
33 |
Execution timed out |
1568 ms |
1748 KB |
Time limit exceeded |
34 |
Execution timed out |
1598 ms |
1748 KB |
Time limit exceeded |
35 |
Execution timed out |
1583 ms |
3684 KB |
Time limit exceeded |
36 |
Execution timed out |
1577 ms |
3592 KB |
Time limit exceeded |
37 |
Execution timed out |
1580 ms |
2808 KB |
Time limit exceeded |
38 |
Execution timed out |
1577 ms |
3812 KB |
Time limit exceeded |
39 |
Execution timed out |
1589 ms |
1996 KB |
Time limit exceeded |
40 |
Execution timed out |
1578 ms |
2384 KB |
Time limit exceeded |
41 |
Execution timed out |
1589 ms |
2568 KB |
Time limit exceeded |
42 |
Execution timed out |
1585 ms |
2528 KB |
Time limit exceeded |
43 |
Execution timed out |
1592 ms |
2892 KB |
Time limit exceeded |
44 |
Execution timed out |
1575 ms |
3284 KB |
Time limit exceeded |
45 |
Execution timed out |
1594 ms |
2808 KB |
Time limit exceeded |
46 |
Execution timed out |
1590 ms |
3716 KB |
Time limit exceeded |
47 |
Execution timed out |
1585 ms |
3680 KB |
Time limit exceeded |
48 |
Execution timed out |
1592 ms |
3696 KB |
Time limit exceeded |
49 |
Execution timed out |
1587 ms |
3716 KB |
Time limit exceeded |
50 |
Execution timed out |
1599 ms |
1996 KB |
Time limit exceeded |