Submission #91348

#TimeUsernameProblemLanguageResultExecution timeMemory
91348Just_Solve_The_ProblemMarriage questions (IZhO14_marriage)C++11
68 / 100
1583 ms4644 KiB
#include <bits/stdc++.h> using namespace std; #define ok puts("ok"); #define ll long long const int N = (int)2e3 + 7; int n, m, k; vector < int > gr[N]; pair < int, int > lr[N]; int used[N], mt[(int)3e4 + 7], prr[N], cnt = 1; int val; bool kuhn(int v) { if (used[v] == cnt) return false; used[v] = cnt; for (int i = lr[v].first; i < gr[v].size(); i++) { int to = gr[v][i]; if (to > val) break; if (mt[to] == -1 || kuhn(mt[to])) { mt[to] = v; prr[v] = to; return true; } } return false; } int check(int l) { for (int i = 1; i <= m; i++) { while (lr[i].first < (int)gr[i].size() && gr[i][lr[i].first] < l) lr[i].first++; } memset(mt, -1, sizeof mt); memset(prr, -1, sizeof prr); int run = 1; while (run) { run = 0; for (int i = 1; i <= m; i++) { if (prr[i] == -1 && kuhn(i)) { run = 1; } } cnt++; } int mx = 0; for (int i = 1; i <= m; i++) { if (prr[i] == -1) { return n + 1; } mx = max(mx, prr[i]); } return mx; } main() { scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= k; i++) { int a, b; scanf("%d %d", &a, &b); gr[b].push_back(a); } ll ans = 0; for (int i = 1; i <= m; i++) { sort(gr[i].begin(), gr[i].end()); lr[i].first = 0; } for (int i = 1; i <= n - m + 1; i++) { int l = i; int r = n + 1; while (r - l > 1) { int mid = (l + r) >> 1; val = mid; int res = check(i); if (res != n + 1) { r = res; } else { l = mid; } } //cout << i << ' ' << r << endl; ans += (n - r + 1); } cout << ans << endl; }

Compilation message (stderr)

marriage.cpp: In function 'bool kuhn(int)':
marriage.cpp:21:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = lr[v].first; i < gr[v].size(); i++) {
                            ~~^~~~~~~~~~~~~~
marriage.cpp: At global scope:
marriage.cpp:59:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...