Submission #905028

# Submission time Handle Problem Language Result Execution time Memory
905028 2024-01-12T13:06:57 Z akliu Job Scheduling (CEOI12_jobs) C++11
60 / 100
1000 ms 42728 KB
#include <bits/stdc++.h>
 
using namespace std;
 
void fastio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
 
void open(string filename) {
    fastio();
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}
 
typedef long long ll;
#define vll vector<ll>
#define vint vector<int>
#define vbool vector<bool>
#define vpii vector<pii>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ins(x) insert(x)
#define sz() size()
#define lb() lower_bound()
#define ub() upper_bound()
#define rsz resize
#define se second
#define fi first
#define cont continue
 
struct g {
    int day, n;
};

bool cmp(const g &x, const g &y) {
    if (x.day != y.day) return x.day < y.day;
    return x.n < y.n;
};


int N, D, M;
set<g, bool (*)(const g &, const g &)> v(cmp);

bool check(int m) {
    // Iterate to check if the minimum is valid
    multiset<int> machines;
    multiset<int> q;
    int d = 0;
    auto it = v.begin();
    g val = *it;
    while (d != N + 1) {
        if (q.sz()) {
            if (d - *(q.begin()) > D) {
                return false;
            }
        }
        machines.clear();
        while (machines.sz() != m) {
            if (!q.sz()) break;
            machines.ins(*(q.begin()));
            q.erase(q.begin());
        }
        while (val.day == d) {
            if (machines.sz() != m) machines.ins(val.day);
            else q.ins(val.day);
            ++it;
            if (it == v.end()) break;
            val = *it;
        }
        ++d;
    }
    return true;
}

void solve() {
    // Input
    cin >> N >> D >> M;
    for (int i = 0; i < M; ++i) {
        int a; cin >> a;
        g val = {a, i+1};
        v.ins(val);
    }

    // Binary search
    int l = 1, r = 1e6, m;
    while (l < r) {
        m = (l + r) / 2;
        if (check(m)) r = m;
        else l = m + 1;
    }
    cout << l << "\n";

    // Iterate once more with the correct minimum
    vector<vint> ans(N + 1);
    multiset<pii> machines;
    multiset<pii> q;
    int d = 0;
    auto it = v.begin();
    g val = *it;
    while (d != N + 1) {
        machines.clear();
        while (machines.sz() != l && q.sz()) {
            pii valQ = *(q.begin());
            machines.ins(mp(valQ.fi, valQ.se));
            q.erase(q.begin());
        }
        while (val.day == d) {
            if (machines.sz() != l) {
                machines.ins(mp(val.day, val.n));
            }
            else q.ins(mp(val.day, val.n));
            ++it;
            if (it == v.end()) break;
            val = *it;
        }
        for (auto &x : machines) {
            ans[d].pb(x.se);
        }
        ++d;
    }

    // Output
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < ans[i].sz(); ++j) {
            cout << ans[i][j] << " ";
        }
        cout << "0\n";
    }
}
 
int main() {
    fastio();
    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
 
    return 0;
}

Compilation message

jobs.cpp: In function 'bool check(int)':
jobs.cpp:61:30: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |         while (machines.sz() != m) {
      |                ~~~~~~~~~~~~~~^~~~
jobs.cpp:67:31: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   67 |             if (machines.sz() != m) machines.ins(val.day);
      |                 ~~~~~~~~~~~~~~^~~~
jobs.cpp: In function 'void solve()':
jobs.cpp:105:30: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  105 |         while (machines.sz() != l && q.sz()) {
      |                ~~~~~~~~~~~~~~^~~~
jobs.cpp:111:31: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  111 |             if (machines.sz() != l) {
      |                 ~~~~~~~~~~~~~~^~~~
jobs.cpp:127:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         for (int j = 0; j < ans[i].sz(); ++j) {
      |                           ^
jobs.cpp: In function 'void open(std::string)':
jobs.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 412 ms 10984 KB Output is correct
2 Correct 415 ms 10964 KB Output is correct
3 Correct 431 ms 10984 KB Output is correct
4 Correct 353 ms 10920 KB Output is correct
5 Correct 407 ms 10984 KB Output is correct
6 Correct 441 ms 11224 KB Output is correct
7 Correct 353 ms 10964 KB Output is correct
8 Correct 401 ms 10980 KB Output is correct
9 Correct 241 ms 9040 KB Output is correct
10 Correct 288 ms 9472 KB Output is correct
11 Correct 218 ms 6212 KB Output is correct
12 Correct 700 ms 12920 KB Output is correct
13 Execution timed out 1012 ms 15700 KB Time limit exceeded
14 Execution timed out 1012 ms 19280 KB Time limit exceeded
15 Execution timed out 1055 ms 23932 KB Time limit exceeded
16 Execution timed out 1046 ms 28420 KB Time limit exceeded
17 Execution timed out 1018 ms 33104 KB Time limit exceeded
18 Execution timed out 1066 ms 37812 KB Time limit exceeded
19 Execution timed out 1049 ms 42728 KB Time limit exceeded
20 Execution timed out 1043 ms 33104 KB Time limit exceeded