제출 #1088806

#제출 시각아이디문제언어결과실행 시간메모리
1088806KasymK결혼 문제 (IZhO14_marriage)C++17
54 / 100
1598 ms5936 KiB
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization ("03")
#pragma GCC optimization ("unroll-loops")
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;
pii p[N];
int ed[N], st[N], n, m, k, love[N];
bool vis[N];
vector<pii> v;
vector<int> adj[N];
 
bool check(){
    set<int> st;
    for(auto &i : v)
        st.insert(i.ss);
    return ((int)st.size() == m);
}
 
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);
        p[i].ff = a, p[i].ss = b;
    }
    sort(p+1, p+k+1);
    int _ = -1;
    for(int i = 1; i <= k; ++i){
        ed[p[i].ff] = i;
        if(p[i].ff != _)
            st[p[i].ff] = i;
        _ = p[i].ff;
    }
    for(int i = 1; i <= n; ++i)
        if (!ed[i])
            ed[i] = ed[i-1];
    st[n+1] = k+1;
    for(int i = n; i >= 1; i--)
        if (!st[i])
            st[i] = st[i+1];
    int answer = 0;
    for(int l = 1; l <= n; ++l)
        for(int r = l; r <= n; ++r){
            v.clear();
            for(int j = st[l]; j <= ed[r]; ++j)
                v.pb(p[j]);
            if(!check())
                continue;
            for(auto &i : v)
                adj[i.ff].pb(i.ss);
            for(int i = 1; i <= m; ++i)
                love[i] = -1;
            for(int i = l; i <= r; ++i){
                for(int j = l; j <= r; ++j)
                    vis[j] = 0;
                kuhn(i);
            }
            bool ok = 1;
            for(int i = 1; i <= m and ok; ++i)
                ok &= (love[i] != -1);
            for(int i = l; i <= r; ++i)
                adj[i].clear();
            if(ok){
                answer += n-r+1;
                break;
            }
        }
    printf("%d\n", answer);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

marriage.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("03")
      | 
marriage.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      | 
marriage.cpp: In function 'int main()':
marriage.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d%d%d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...