Submission #171981

#TimeUsernameProblemLanguageResultExecution timeMemory
171981DeD_TihoNMarriage questions (IZhO14_marriage)C++14
80 / 100
1562 ms3192 KiB
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define endl '\n'
#define y1 yaumru
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter vector<int>::iterator
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=30000+7;
const int inf=1e18+5;
const int mod=1e9+7;
const ld eps=1e-9;

vector<int>g[N];
bool used[N];
int mt[N];
int n,m;
bool used1[N];

bool try_kuhn (int v,int l,int r) {
	if (used[v])  return false;
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (to<l || to>r)continue;
		if (mt[to] == -1 || try_kuhn (mt[to],l,r)) {
			mt[to] = v;
			return true;
		}
	}
	return false;
}

bool check(int l,int r)
{
    fill(mt,mt+n+1,-1);
    fill(used1,used1+m+1,false);
    for (int i=1;i<=m;++i){
        for (int j=0;j<g[i].size();++j){
            int to=g[i][j];
            if (to>=l && to<=r){
                if (mt[to]==-1){
                    mt[to]=i;
                    used1[i]=true;
                    break;
                }
            }
        }
    }
    for (int i=1;i<=m;++i){
        if (used1[i])continue;
        fill(used,used+m+1,false);
        try_kuhn(i,l,r);
    }
    int ans=0;
    for (int i=1;i<=n;++i){
        if (mt[i]!=-1)++ans;
    }
    if (ans!=m)return false;
    return true;
}

main ()
{
    ios;
    int k;
    cin>>n>>m>>k;
    for (int i=1;i<=k;++i){
        int x,y;
        cin>>x>>y;
        swap(x,y);
        g[x].pb(y);
    }
    int ans=0;
    int r=1;
    for (int i=1;i<=n;++i){
        while(r<=n && !check(i,r))++r;
        ans+=n-r+1;
    }
    cout<<ans<<endl;
}

Compilation message (stderr)

marriage.cpp: In function 'bool check(long long int, long long int)':
marriage.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j=0;j<g[i].size();++j){
                      ~^~~~~~~~~~~~
marriage.cpp: At global scope:
marriage.cpp:87:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
#Verdict Execution timeMemoryGrader output
Fetching results...