제출 #1242350

#제출 시각아이디문제언어결과실행 시간메모리
1242350KindaGoodGames팀들 (IOI15_teams)C++20
21 / 100
4094 ms47276 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]}; } sort(arr.begin(),arr.end(),[](pii a, pii b){ if(a.first != b.first) return a.first < b.first; return (a.second-a.first) < (b.second-b.first); }); } 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); set<pii> left; int pt = 0; for(int i = 0; i < m; i++){ for(int j = 0; j < K[i]; j++){ left.insert({K[i], pt}); 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++){ // auto it = left.lower_bound({arr[i].first, -1}); // while(it != left.end() && (*it).second <= arr[i].second){ // int u = (*it).first; // if(from[u] == -1){ // from[u] = i; // matched[i] = true; // left.erase(it); // break; // } // it++; // } // } 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...