Submission #443062

# Submission time Handle Problem Language Result Execution time Memory
443062 2021-07-09T14:58:23 Z leaked Marriage questions (IZhO14_marriage) C++14
14 / 100
35 ms 5560 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define vec vector
#define sz(x) ( int)x.size()
#define m_p make_pair
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef unsigned long long ull;
auto rng=bind(uniform_int_distribution<int>(1,1000),mt19937(time(0)));
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const int N=3e4+1;
const int K=165;
const int M=2001;
vec<int> g[N+M];
int uk;
int mt[N+M];
int h[N+M],u[N+M],tt,n,m;
int tr;
vec<int>rem;
bool kuhn(int v){
    if(u[v]==tt) return 0;
    u[v]=tt;
    for(auto &z : g[v]){
        if(h[z] && mt[z]==v){
            assert(false);
        }
        if(!h[z]) assert(mt[z]==-1);
    }
    for(auto &z : g[v]){
        if(h[z] && (mt[z]==-1 || kuhn(mt[z]))){
            mt[z]=v;mt[v]=z;
            return 1;
        }
    }
    return 0;
}
signed main(){
//    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<k;i++){
        int v,u;
        scanf("%d%d",&v,&u);--v;--u;
        g[v].pb(u+n);
        g[u+n].pb(v);
    }
    fill(mt,mt+n+m,-1);
    for(int i=0;i<m;i++) h[i+n]=1,rem.pb(i+n);
    int r=-1;
    int c=0;
    ll ans=0;
    for(int l=0;l<n;l++){
        if(l){
            h[l-1]=0;
            if(mt[l-1]!=-1){
                tt++;
                rem.pb(mt[l-1]);
                mt[rem.back()]=-1;
                mt[l-1]=-1;
            }
        }
        while(sz(rem) && kuhn(rem.back())){
            rem.pop_back();
        }
        while(r<n && sz(rem)){
            r++;tt++;h[r]=1;
            while(sz(rem) && kuhn(rem.back())){
                rem.pop_back();
            }
        }
        ans+=n-r;
    }
    printf("%lld",ans);
    return 0;
}

/*
5
1 2
2 3
3 4
4 5
5 1
*/

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:62:9: warning: unused variable 'c' [-Wunused-variable]
   62 |     int c=0;
      |         ^
marriage.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d%d%d",&n,&m,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
marriage.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf("%d%d",&v,&u);--v;--u;
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1996 KB Execution killed with signal 6
2 Runtime error 2 ms 1996 KB Execution killed with signal 6
3 Runtime error 2 ms 1996 KB Execution killed with signal 6
4 Runtime error 2 ms 1996 KB Execution killed with signal 6
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Runtime error 2 ms 1996 KB Execution killed with signal 6
8 Correct 1 ms 972 KB Output is correct
9 Runtime error 2 ms 1996 KB Execution killed with signal 6
10 Runtime error 2 ms 1996 KB Execution killed with signal 6
11 Runtime error 2 ms 1996 KB Execution killed with signal 6
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Runtime error 2 ms 1996 KB Execution killed with signal 6
15 Runtime error 2 ms 1996 KB Execution killed with signal 6
16 Runtime error 2 ms 1996 KB Execution killed with signal 6
17 Runtime error 2 ms 1996 KB Execution killed with signal 6
18 Runtime error 2 ms 1996 KB Execution killed with signal 6
19 Runtime error 2 ms 1996 KB Execution killed with signal 6
20 Runtime error 2 ms 1996 KB Execution killed with signal 6
21 Runtime error 2 ms 1996 KB Execution killed with signal 6
22 Runtime error 2 ms 1964 KB Execution killed with signal 6
23 Runtime error 2 ms 1996 KB Execution killed with signal 6
24 Runtime error 2 ms 1996 KB Execution killed with signal 6
25 Runtime error 5 ms 2380 KB Execution killed with signal 6
26 Runtime error 2 ms 1996 KB Execution killed with signal 6
27 Runtime error 2 ms 1996 KB Execution killed with signal 6
28 Runtime error 2 ms 1996 KB Execution killed with signal 6
29 Runtime error 4 ms 2252 KB Execution killed with signal 6
30 Runtime error 4 ms 2252 KB Execution killed with signal 6
31 Runtime error 13 ms 3128 KB Execution killed with signal 6
32 Runtime error 3 ms 2252 KB Execution killed with signal 6
33 Correct 1 ms 1100 KB Output is correct
34 Runtime error 2 ms 2124 KB Execution killed with signal 6
35 Runtime error 22 ms 4112 KB Execution killed with signal 6
36 Runtime error 20 ms 4136 KB Execution killed with signal 6
37 Runtime error 15 ms 3532 KB Execution killed with signal 6
38 Runtime error 23 ms 4696 KB Execution killed with signal 6
39 Runtime error 3 ms 2380 KB Execution killed with signal 6
40 Correct 5 ms 1356 KB Output is correct
41 Runtime error 9 ms 3040 KB Execution killed with signal 6
42 Runtime error 11 ms 3400 KB Execution killed with signal 6
43 Runtime error 17 ms 3660 KB Execution killed with signal 6
44 Runtime error 26 ms 4592 KB Execution killed with signal 6
45 Runtime error 13 ms 4056 KB Execution killed with signal 6
46 Runtime error 32 ms 5444 KB Execution killed with signal 6
47 Runtime error 32 ms 5312 KB Execution killed with signal 6
48 Runtime error 30 ms 5360 KB Execution killed with signal 6
49 Runtime error 35 ms 5560 KB Execution killed with signal 6
50 Runtime error 4 ms 2636 KB Execution killed with signal 6