답안 #92706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92706 2019-01-04T10:38:13 Z Aydarov03 결혼 문제 (IZhO14_marriage) C++14
100 / 100
347 ms 2316 KB
#include <bits/stdc++.h>
using namespace std;
const int M = 2e3 + 5;

vector <int> g[M];
queue <int> q;
int used[M] , cnt = 1 , mt[30005] , l , r , ans;

bool khun( int v )
{
    if( used[v] == cnt )
        return false;
    used[v] = cnt;

    for(auto to : g[v])
    {
        if(to < l)continue;
        if(to > r)break;

        if( mt[to] == -1 || khun( mt[to] ) )
        {
            mt[to] = v;
            return true;
        }
    }
    return false;
}


bool check()
{
    while( !q.empty() )
    {
        int v = q.front();
        q.pop();
        cnt++;
        if( !khun(v) )
        {
            q.push(v);
            return false;
        }
    }

    return true;
}


main()
{
    int n , m , k;
    cin >> n >> m >> k;

    for(int i = 1; i <= k; i++)
    {
        int a , b;
        scanf("%d %d" , &a , &b);
        g[b].push_back( a );
    }

	memset(mt, -1, sizeof mt);
    for(int i = 1; i <= m; i++){
        sort( g[i].begin() , g[i].end() );
        q.push(i);
    }

    r = 1;

    for(int i = 1; i <= n; i++)
    {
        l = i;
        while(r <= n && !check() )
            r++;

        ans += (n - r + 1);

        if( mt[i] != -1 )
        {
            q.push( mt[i] );
            mt[i] = -1;
        }
    }

    cout << ans;

}

Compilation message

marriage.cpp:48:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
marriage.cpp: In function 'int main()':
marriage.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d" , &a , &b);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 508 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 500 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 14 ms 632 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 110 ms 1144 KB Output is correct
32 Correct 8 ms 632 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 5 ms 504 KB Output is correct
35 Correct 85 ms 1784 KB Output is correct
36 Correct 64 ms 1660 KB Output is correct
37 Correct 347 ms 1272 KB Output is correct
38 Correct 20 ms 1884 KB Output is correct
39 Correct 101 ms 632 KB Output is correct
40 Correct 5 ms 632 KB Output is correct
41 Correct 9 ms 888 KB Output is correct
42 Correct 8 ms 888 KB Output is correct
43 Correct 11 ms 1192 KB Output is correct
44 Correct 19 ms 1912 KB Output is correct
45 Correct 12 ms 1016 KB Output is correct
46 Correct 183 ms 2168 KB Output is correct
47 Correct 20 ms 2040 KB Output is correct
48 Correct 19 ms 1912 KB Output is correct
49 Correct 261 ms 2316 KB Output is correct
50 Correct 208 ms 892 KB Output is correct