Submission #684050

#TimeUsernameProblemLanguageResultExecution timeMemory
684050pragmatistMarriage questions (IZhO14_marriage)C++17
52 / 100
1588 ms3192 KiB
/* #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 timeMemoryGrader output
Fetching results...