Submission #117503

#TimeUsernameProblemLanguageResultExecution timeMemory
117503zubecTeams (IOI15_teams)C++14
0 / 100
4086 ms58032 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 mt[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; i++){
        used[i] = 0;
        g[i].clear();
        add[i].clear();
    }
    for (int i = 1; i <= n; i++){
        add[a[i].second].push_back(i);
        add[a[i].first-1].push_back(-i);
    }
    for (int i = 1; i <= M; i++){
        int need = K[i-1];
        g[need].push_back(i);
    }
    multiset<pair<int, int> > q;
    for (int i = n; i >= 1; i--){
        for (int j = 0; j < add[i].size(); j++){
            int id = add[i][j];
            if (id > 0)
                q.insert({a[id].first, id});
            else
                if (!used[-id])
                    q.erase(q.find({a[-id].first, -id}));
        }
        for (int j = 0; j < g[i].size(); j++){
            int need = g[i][j];
            if (q.size() < need)
                return 0;
            for (int j = 0; j < need; j++){
                used[prev(q.end())->second] = 1;
                q.erase(prev(q.end()));
            }
        }
    }
    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)
                 ~~~~~~~~~^~~~~~
teams.cpp:58:22: warning: declaration of 'j' shadows a previous local [-Wshadow]
             for (int j = 0; j < need; j++){
                      ^
teams.cpp:54:18: note: shadowed declaration is here
         for (int j = 0; j < g[i].size(); j++){
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...