Submission #1242243

#TimeUsernameProblemLanguageResultExecution timeMemory
1242243KindaGoodGamesTeams (IOI15_teams)C++20
21 / 100
4097 ms23876 KiB
#include "teams.h" #include<bits/stdc++.h> using namespace std; #define pii pair<int,int> int n; vector<pii> arr; vector<int> sz; int s; void init(int N, int A[], int B[]) { n = N; arr.resize(n); for(int i = 0; i < n; i++){ arr[i] = {A[i], B[i]}; } } bool doMatch(int v, vector<int>& from, vector<vector<int>>& adj, vector<bool>& vis){ if(vis[v]) return false; vis[v] = true; int lo = lower_bound(sz.begin(),sz.end(), arr[v].first)-sz.begin(); int hi = upper_bound(sz.begin(),sz.end(), arr[v].second)-sz.begin(); for(int u = lo; u < hi; u++){ if(sz[u] > arr[v].second || sz[u] < arr[v].first) continue; if(from[u] == -1 || doMatch(from[u],from,adj,vis)){ from[u] = v; return true; } } return false; } int can(int m, int sizes[]) { vector<int> K(m); for(int i = 0; i < m; i++){ K[i] = sizes[i]; } sort(K.begin(),K.end()); s = 0; for(int i = 0; i < m; i++){ s += K[i]; } if(s > n){ return false; } sz = vector<int>(s); int pt = 0; for(int i = 0; i < m; i++){ for(int j = 0; j < K[i]; j++){ sz[pt++] = K[i]; } } vector<vector<int>> adj(n); vector<bool> vis(n); vector<bool> matched(n); vector<int> from(s, -1); // for(int i = 0; i < n; i++){ // for(auto u : adj[i]){ // if(from[u] == -1){ // from[u] = i; // matched[i] = true; // break; // } // } // } for(int i = 0; i < n; i++){ if(matched[i]) continue; fill(vis.begin(),vis.end(),0); doMatch(i,from, adj,vis); } for(int i = 0; i < s; i++){ if(from[i] == -1){ return false; } } return true; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...