# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117506 | zubec | Teams (IOI15_teams) | C++14 | 4091 ms | 46496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |