답안 #582077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582077 2022-06-23T11:01:15 Z FatihSolak 결혼 문제 (IZhO14_marriage) C++17
78 / 100
1500 ms 1744 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);
    }
    vector<int> unmatched;
    for(int i = 1;i<=m;i++){
        unmatched.push_back(i);
    }
    r = 0;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        l = i;
        r = max(r,i+m-1);
        reset(m);
        while(unmatched.size() && try_kuhn(unmatched.back())){
            reset(m);
            unmatched.pop_back();
        }
        while(r != n && unmatched.size()){
            r++;
            reset(m);
            while(unmatched.size() && try_kuhn(unmatched.back())){
                reset(m);
                unmatched.pop_back();
            }
        }
        if(r == n && unmatched.size())break;
        ans += n - r + 1;
        if(mt[i]){
            unmatched.push_back(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 Execution timed out 1581 ms 980 KB Time limit exceeded
2 Execution timed out 1586 ms 980 KB Time limit exceeded
3 Correct 1 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 Execution timed out 1586 ms 980 KB Time limit exceeded
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 940 KB Output is correct
10 Execution timed out 1577 ms 980 KB Time limit exceeded
11 Execution timed out 1598 ms 980 KB Time limit exceeded
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Execution timed out 1591 ms 980 KB Time limit exceeded
16 Correct 1 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 Execution timed out 1600 ms 980 KB Time limit exceeded
20 Execution timed out 1574 ms 980 KB Time limit exceeded
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Execution timed out 1580 ms 1108 KB Time limit exceeded
26 Correct 3 ms 980 KB Output is correct
27 Correct 1 ms 1024 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 2 ms 980 KB Output is correct
30 Correct 2 ms 980 KB Output is correct
31 Execution timed out 1578 ms 1364 KB Time limit exceeded
32 Correct 2 ms 1108 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 2 ms 980 KB Output is correct
35 Correct 30 ms 1560 KB Output is correct
36 Correct 24 ms 1544 KB Output is correct
37 Execution timed out 1587 ms 1364 KB Time limit exceeded
38 Correct 15 ms 1532 KB Output is correct
39 Correct 46 ms 1092 KB Output is correct
40 Correct 3 ms 1108 KB Output is correct
41 Correct 5 ms 1236 KB Output is correct
42 Correct 6 ms 1236 KB Output is correct
43 Correct 9 ms 1268 KB Output is correct
44 Correct 17 ms 1552 KB Output is correct
45 Correct 9 ms 1296 KB Output is correct
46 Correct 22 ms 1668 KB Output is correct
47 Correct 20 ms 1620 KB Output is correct
48 Correct 18 ms 1620 KB Output is correct
49 Correct 24 ms 1744 KB Output is correct
50 Correct 150 ms 1168 KB Output is correct