Submission #341265

# Submission time Handle Problem Language Result Execution time Memory
341265 2020-12-29T10:22:31 Z juggernaut Marriage questions (IZhO14_marriage) C++14
100 / 100
826 ms 2156 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,qq,mt[30005],GL,GR,vis[2005],timer;
vector<int>g[2005];
queue<int>q;
bool kuhn(int v){
    if(vis[v]==timer)return false;
    vis[v]=timer;
    for(int to:g[v]){
        if(to<GL||to>GR)continue;
        if(!mt[to]||kuhn(mt[to])){
            mt[to]=v;
            return true;
        }
    }
    return false;
}
bool check(){
    while(!q.empty()){
        int v=q.front();
        q.pop();
        timer++;
        if(!kuhn(v)){
            q.push(v);
            return false;
        }
    }
    return true;
}
int main(){vector<int>v={1,2,3,4,5,6,7,8,9};
    srand(time(NULL));
    vector<int>v1=v;
    //random_shuffle(v.begin(),v.end());
    for(int i=0;i<9;i++)if(v[i]!=v1[i]){
        puts("SHUFFLE WORKS");
        return 1;
    }
    scanf("%d%d%d",&n,&m,&qq);
    while(qq--){
        int x,y;
        scanf("%d%d",&x,&y);
        g[y].push_back(x);
    }
    for(int i=1;i<=m;i++)q.push(i);
    int ans=0;
    GR=1;
    for(GL=1;GL<=n;GL++){
        while(GR<=n&&!check())GR++;
        ans+=n-GR+1;
        if(mt[GL]){
            q.push(mt[GL]);
            mt[GL]=0;
        }
    }
    cout<<ans;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d%d%d",&n,&m,&qq);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
marriage.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 37 ms 492 KB Output is correct
26 Correct 5 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 3 ms 492 KB Output is correct
31 Correct 284 ms 1128 KB Output is correct
32 Correct 11 ms 492 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 3 ms 364 KB Output is correct
35 Correct 111 ms 1716 KB Output is correct
36 Correct 82 ms 1516 KB Output is correct
37 Correct 826 ms 1388 KB Output is correct
38 Correct 22 ms 1644 KB Output is correct
39 Correct 69 ms 620 KB Output is correct
40 Correct 4 ms 620 KB Output is correct
41 Correct 7 ms 748 KB Output is correct
42 Correct 8 ms 876 KB Output is correct
43 Correct 12 ms 1132 KB Output is correct
44 Correct 22 ms 1772 KB Output is correct
45 Correct 10 ms 1004 KB Output is correct
46 Correct 46 ms 2028 KB Output is correct
47 Correct 24 ms 2028 KB Output is correct
48 Correct 22 ms 1900 KB Output is correct
49 Correct 88 ms 2156 KB Output is correct
50 Correct 173 ms 620 KB Output is correct