답안 #582064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582064 2022-06-23T10:50:54 Z FatihSolak 결혼 문제 (IZhO14_marriage) C++17
68 / 100
222 ms 2688 KB
#include <bits/stdc++.h>
#define N 30005
using namespace std;
vector<int> adj[N];
int mt[N];
int l,r;
bool vis[N];
void reset(int x){
    for(int i = 0;i<=x;i++){
        vis[i] = 0;
    }
}
bool try_kuhn(int v){
    if(vis[v])
        return 0;
    vis[v] = 1;
    for(auto u:adj[v]){
        if(u < l || r < u)continue;
        if(mt[u] == 0 || try_kuhn(mt[u])){
            mt[u] = v;
            return 1;
        }
    }
    return 0;
}
void solve(){
    int n,m,k;
    cin >> n >> m >> k;
    for(int i = 1;i<=k;i++){
        int u,v;
        cin >> u >> v;
        adj[v].push_back(u);
    }
    set<int> unmatched;
    for(int i = 1;i<=m;i++){
        unmatched.insert(i);
    }
    r = 0;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        l = i;
        while(r != n && unmatched.size()){
            r++;
            reset(m);
            while(unmatched.size() && try_kuhn(*unmatched.begin())){
                reset(m);
                unmatched.erase(unmatched.begin());
            }
        }
        if(r == n && unmatched.size())break;
        ans += n - r + 1;
        if(mt[i]){
            unmatched.insert(mt[i]);
        }
    }
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    #ifdef Local
        cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 980 KB Output isn't correct
2 Incorrect 1 ms 980 KB Output isn't correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1036 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1036 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 1036 KB Output is correct
12 Correct 1 ms 1076 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 1036 KB Output is correct
15 Correct 1 ms 944 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 2 ms 980 KB Output is correct
23 Correct 1 ms 928 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 8 ms 1108 KB Output is correct
26 Incorrect 2 ms 980 KB Output isn't correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Incorrect 2 ms 1108 KB Output isn't correct
30 Incorrect 2 ms 1108 KB Output isn't correct
31 Correct 74 ms 1728 KB Output is correct
32 Incorrect 2 ms 1108 KB Output isn't correct
33 Correct 1 ms 1056 KB Output is correct
34 Correct 6 ms 1108 KB Output is correct
35 Correct 35 ms 2264 KB Output is correct
36 Correct 29 ms 2196 KB Output is correct
37 Correct 166 ms 1824 KB Output is correct
38 Incorrect 15 ms 2396 KB Output isn't correct
39 Correct 91 ms 1272 KB Output is correct
40 Correct 4 ms 1236 KB Output is correct
41 Incorrect 8 ms 1452 KB Output isn't correct
42 Incorrect 7 ms 1432 KB Output isn't correct
43 Incorrect 11 ms 1748 KB Output isn't correct
44 Incorrect 18 ms 2508 KB Output isn't correct
45 Incorrect 10 ms 1636 KB Output isn't correct
46 Incorrect 27 ms 2552 KB Output isn't correct
47 Incorrect 24 ms 2676 KB Output isn't correct
48 Incorrect 19 ms 2644 KB Output isn't correct
49 Incorrect 31 ms 2688 KB Output isn't correct
50 Correct 222 ms 1452 KB Output is correct