Submission #684050

# Submission time Handle Problem Language Result Execution time Memory
684050 2023-01-20T08:06:47 Z pragmatist Marriage questions (IZhO14_marriage) C++17
52 / 100
1500 ms 3192 KB
/*
#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];

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];
	}
	int ans = 0;
	for(int l = 1; l <= n; ++l) {
		for(int r = l; r <= n; ++r) {
			for(int i = 1; i <= n; ++i) g[i].clear();
			for(int i = n + 1; i <= n + m; ++i) mt[i] = -1;
			for(int i = 1; i <= k; ++i) {
				if(a[i] >= l && a[i] <= r) {
					g[a[i]].pb(b[i] + 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 980 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 1 ms 1040 KB Output is correct
4 Correct 1 ms 1032 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1012 KB Output is correct
8 Correct 1 ms 1028 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1028 KB Output is correct
17 Correct 1 ms 1032 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 167 ms 1072 KB Output is correct
20 Correct 47 ms 1036 KB Output is correct
21 Correct 7 ms 1036 KB Output is correct
22 Correct 5 ms 980 KB Output is correct
23 Correct 38 ms 1060 KB Output is correct
24 Correct 26 ms 980 KB Output is correct
25 Execution timed out 1552 ms 1388 KB Time limit exceeded
26 Execution timed out 1576 ms 1084 KB Time limit exceeded
27 Correct 733 ms 1108 KB Output is correct
28 Correct 419 ms 1036 KB Output is correct
29 Execution timed out 1577 ms 1212 KB Time limit exceeded
30 Execution timed out 1572 ms 1236 KB Time limit exceeded
31 Execution timed out 1575 ms 2120 KB Time limit exceeded
32 Execution timed out 1582 ms 1156 KB Time limit exceeded
33 Execution timed out 1544 ms 980 KB Time limit exceeded
34 Execution timed out 1582 ms 1108 KB Time limit exceeded
35 Execution timed out 1568 ms 3192 KB Time limit exceeded
36 Execution timed out 1580 ms 2892 KB Time limit exceeded
37 Execution timed out 1577 ms 2044 KB Time limit exceeded
38 Execution timed out 1580 ms 3024 KB Time limit exceeded
39 Execution timed out 1585 ms 1208 KB Time limit exceeded
40 Execution timed out 1577 ms 1336 KB Time limit exceeded
41 Execution timed out 1583 ms 1820 KB Time limit exceeded
42 Execution timed out 1588 ms 1748 KB Time limit exceeded
43 Execution timed out 1578 ms 2224 KB Time limit exceeded
44 Execution timed out 1583 ms 2792 KB Time limit exceeded
45 Execution timed out 1581 ms 1936 KB Time limit exceeded
46 Execution timed out 1575 ms 2888 KB Time limit exceeded
47 Execution timed out 1552 ms 3084 KB Time limit exceeded
48 Execution timed out 1569 ms 2788 KB Time limit exceeded
49 Execution timed out 1582 ms 3052 KB Time limit exceeded
50 Execution timed out 1559 ms 1236 KB Time limit exceeded