답안 #1088282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088282 2024-09-14T07:50:28 Z Kerim 결혼 문제 (IZhO14_marriage) C++17
58 / 100
1500 ms 7200 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
int n, m, k, love[N];
bool vis[N], vis1[N], mark[N];
vector<int> adj[N], g[N];

bool kuhn(int x){
    if(vis[x]) 
        return 0;
    vis[x] = 1;
    for(auto i : adj[x])
        if(love[i] == -1 or kuhn(love[i])){
            love[i] = x;
            return 1;
        }
    return 0;
}

int main(){
	// freopen("file.in", "r", stdin);
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 1; i <= k; ++i){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
    }
    int answer = 0;
    for(int l = 1; l <= n; ++l){
        vector<int> v;
        int cnt = 0;
        for(int r = l; r <= n; ++r){
            for(auto &i : g[r]){
                cnt += !mark[i];
                mark[i] = 1;
                adj[r].pb(i);
            }
            if (cnt < m)
                continue;
            for (int i = 1; i <= m; i++)
            	love[i] = -1;
            // Improved Kuhn starts here
            for (int j = l; j <= r; j++)
                vis1[j] = 0;
            for (int j = l; j <= r; j++)
                for (int to : adj[j])
                    if (love[to] == -1) {
                        love[to] = j;
                        vis1[j] = true;
                        break;
                    }
            for (int i = l; i <= r; i++){
                if (vis1[i])
                    continue;
                // Improved Kuhn ends here
            	for (int j = l; j <= r; j++)
            		vis[j] = 0;
            	kuhn(i);
            }
            bool ok = 1;
            for (int i = 1; i <= m; i++)
            	ok &= (love[i] != -1);
            answer += ok;
        }
        for (int i = 1; i <= n; i++)
            adj[i].clear();
        for(int i = 1; i <= m; ++i)
            mark[i] = 0;
    }
    printf("%d\n", answer);
    return 0;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d%d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4932 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5152 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 2 ms 5096 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 5056 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 4 ms 4956 KB Output is correct
19 Correct 38 ms 4956 KB Output is correct
20 Correct 23 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 10 ms 5164 KB Output is correct
24 Correct 7 ms 4956 KB Output is correct
25 Execution timed out 1600 ms 5276 KB Time limit exceeded
26 Execution timed out 1514 ms 4952 KB Time limit exceeded
27 Correct 3 ms 4952 KB Output is correct
28 Correct 162 ms 5136 KB Output is correct
29 Execution timed out 1548 ms 5208 KB Time limit exceeded
30 Execution timed out 1575 ms 5212 KB Time limit exceeded
31 Execution timed out 1513 ms 5676 KB Time limit exceeded
32 Execution timed out 1562 ms 5220 KB Time limit exceeded
33 Correct 7 ms 5164 KB Output is correct
34 Correct 628 ms 4956 KB Output is correct
35 Execution timed out 1546 ms 6168 KB Time limit exceeded
36 Execution timed out 1518 ms 5980 KB Time limit exceeded
37 Execution timed out 1572 ms 5672 KB Time limit exceeded
38 Execution timed out 1574 ms 6492 KB Time limit exceeded
39 Execution timed out 1593 ms 5384 KB Time limit exceeded
40 Correct 350 ms 5468 KB Output is correct
41 Execution timed out 1578 ms 5464 KB Time limit exceeded
42 Execution timed out 1570 ms 5980 KB Time limit exceeded
43 Execution timed out 1560 ms 5980 KB Time limit exceeded
44 Execution timed out 1553 ms 6384 KB Time limit exceeded
45 Execution timed out 1551 ms 6132 KB Time limit exceeded
46 Execution timed out 1570 ms 6108 KB Time limit exceeded
47 Execution timed out 1558 ms 7200 KB Time limit exceeded
48 Execution timed out 1595 ms 6744 KB Time limit exceeded
49 Execution timed out 1540 ms 6228 KB Time limit exceeded
50 Execution timed out 1545 ms 5208 KB Time limit exceeded