Submission #38511

# Submission time Handle Problem Language Result Execution time Memory
38511 2018-01-04T10:32:37 Z alenam0161 Marriage questions (IZhO14_marriage) C++14
66 / 100
1500 ms 3852 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e4+7;
vector<int> g[N],g1[N];
int n,m,k;
bool used[N];
int ma[N];
bool try_khun(int v){
    if(used[v]==true)return false;
    used[v]=true;
    for(auto to:g[v]){
        if(ma[to]==-1||try_khun(ma[to])){
            ma[to]=v;
            return true;
        }
    }
    return false;
}
int main(){
    memset(ma,-1,sizeof(ma));
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=k;++i){
        int u,v;
        scanf("%d%d",&v,&u);
        g[v].push_back(u);
        g1[u].push_back(v);
    }
    int how=0;
    long long ans=0;
    int l=1;
    bool ok=false;
    for(int i=1;i<=n;++i){
        if(try_khun(i))how++;
        bool ok=false;
        while(how==m||ok==false){
            l++;
            ok=true;
            how=0;
            memset(ma,-1,sizeof(ma));
            for(int j=l;j<=i;++j){
                memset(used,0,sizeof(used));
                how+=try_khun(j);
            }
        }
        l--;
        memset(used,0,sizeof(used));
        how+=try_khun(l);
    //    cout<<l<<" "<<i<<" "<<how<<endl;
        if(how==m)
        ans+=l;
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:33:10: warning: unused variable 'ok' [-Wunused-variable]
     bool ok=false;
          ^
marriage.cpp:23:29: 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:26:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v,&u);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2532 KB Output is correct
2 Correct 0 ms 2532 KB Output is correct
3 Correct 0 ms 2532 KB Output is correct
4 Correct 0 ms 2532 KB Output is correct
5 Correct 0 ms 2532 KB Output is correct
6 Correct 0 ms 2532 KB Output is correct
7 Correct 0 ms 2532 KB Output is correct
8 Correct 0 ms 2532 KB Output is correct
9 Correct 0 ms 2532 KB Output is correct
10 Correct 0 ms 2532 KB Output is correct
11 Correct 0 ms 2532 KB Output is correct
12 Correct 0 ms 2532 KB Output is correct
13 Correct 0 ms 2532 KB Output is correct
14 Correct 0 ms 2532 KB Output is correct
15 Correct 0 ms 2532 KB Output is correct
16 Correct 0 ms 2532 KB Output is correct
17 Correct 0 ms 2532 KB Output is correct
18 Correct 0 ms 2532 KB Output is correct
19 Correct 0 ms 2532 KB Output is correct
20 Correct 0 ms 2532 KB Output is correct
21 Correct 0 ms 2532 KB Output is correct
22 Correct 0 ms 2532 KB Output is correct
23 Correct 3 ms 2532 KB Output is correct
24 Correct 3 ms 2532 KB Output is correct
25 Correct 36 ms 2664 KB Output is correct
26 Correct 59 ms 2532 KB Output is correct
27 Correct 23 ms 2532 KB Output is correct
28 Correct 33 ms 2532 KB Output is correct
29 Correct 639 ms 2664 KB Output is correct
30 Correct 556 ms 2664 KB Output is correct
31 Correct 613 ms 3060 KB Output is correct
32 Execution timed out 1500 ms 2664 KB Execution timed out
33 Correct 96 ms 2532 KB Output is correct
34 Correct 786 ms 2532 KB Output is correct
35 Execution timed out 1500 ms 3588 KB Execution timed out
36 Execution timed out 1500 ms 3588 KB Execution timed out
37 Execution timed out 1500 ms 3192 KB Execution timed out
38 Execution timed out 1500 ms 3852 KB Execution timed out
39 Execution timed out 1500 ms 2664 KB Execution timed out
40 Execution timed out 1500 ms 2796 KB Execution timed out
41 Execution timed out 1500 ms 2928 KB Execution timed out
42 Runtime error 6 ms 2928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 6 ms 3060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 23 ms 3456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 0 ms 2532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 0 ms 2532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 6 ms 3060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 6 ms 3060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 0 ms 2532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 0 ms 2532 KB Execution killed with signal 11 (could be triggered by violating memory limits)