Submission #117506

#TimeUsernameProblemLanguageResultExecution timeMemory
117506zubecTeams (IOI15_teams)C++14
34 / 100
4091 ms46496 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 500100; vector <int> g[N]; vector <int> add[N]; pair<int, int> a[N]; int n; void init(int N, int A[], int B[]) { n = N; for (int i = 1; i <= n; i++){ a[i] = {A[i-1], B[i-1]}; } } bool used[N]; int can(int M, int K[]) { ll sum = 0; for (int i = 1; i <= M; i++){ sum += K[i-1]; } if (sum > n) return 0; for (int i = 0; i <= n+1; i++){ used[i] = 0; g[i].clear(); add[i].clear(); } for (int i = 1; i <= n; i++){ add[a[i].first].push_back(i); add[a[i].second+1].push_back(-i); } for (int i = 1; i <= M; i++){ int need = K[i-1]; g[need].push_back(i); } set<pair<int, int> > q; for (int i = 1; i <= n; i++){ for (int j = 0; j < add[i].size(); j++){ int id = add[i][j]; if (id > 0) q.insert({a[id].second, id}); else if (!used[-id]) q.erase(q.find({a[-id].second, -id})); } for (int j = 0; j < g[i].size(); j++){ int need = K[g[i][j]-1]; if (q.size() < need) return 0; for (int l = 0; l < need; l++){ used[q.begin()->second] = 1; q.erase(q.begin()); } } } return 1; }

Compilation message (stderr)

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:15:34: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 void init(int N, int A[], int B[]) {
                                  ^
teams.cpp:6:11: note: shadowed declaration is here
 const int N = 500100;
           ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:46:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < add[i].size(); j++){
                         ~~^~~~~~~~~~~~~~~
teams.cpp:54:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < g[i].size(); j++){
                         ~~^~~~~~~~~~~~~
teams.cpp:56:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (q.size() < need)
                 ~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...