Submission #733407

# Submission time Handle Problem Language Result Execution time Memory
733407 2023-04-30T16:33:17 Z jared Job Scheduling (CEOI12_jobs) C++14
40 / 100
377 ms 20260 KB
#include <bits/stdc++.h>

#ifdef LOCAL_TEST

#include "debugging.h"

#endif

using namespace std;

void setio(string filename) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (getenv("stdio")) filename = "";
    else if (getenv("local_test")) filename = "test";

    if (!filename.empty()) {
        freopen((filename + ".in").c_str(), "r", stdin);
        freopen((filename + ".out").c_str(), "w", stdout);
    }
}

vector<vector<int>> days;

bool ok(vector<pair<int, int>> &x, int n, int d, int target, bool out) {
    int ptr = 0;
    for (int day = 1; day <= n; day++) {
        if (ptr >= x.size()) break;

        int daily_cnt = target;
        while (daily_cnt--) {
            if (x[ptr].first > day) break;
            if (day - x[ptr].first > d) return false;
            if (out) days[day - 1].push_back(x[ptr].second);
            ptr++;
        }
    }
    return ptr >= x.size();
}

int main() {
    setio("");

    int n, d, m;
    cin >> n >> d >> m;
    vector<pair<int, int>> x;
    for (int i = 1; i <= m; i++) {
        int tmp;
        cin >> tmp;
        x.emplace_back(tmp, i);
    }
    sort(x.begin(), x.end());

    int l = 1, r = m;
    while (l < r) {
        int mid = l + (r - l) / 2;

        days.clear();
        if (ok(x, n, d, mid, false)) r = mid;
        else l = mid + 1;
    }

    cout << l << endl;
    days.resize(n);
    ok(x, n, d, l, true);
    for (auto &day: days) {
        for (int id: day)
            cout << id << ' ';
        cout << 0 << endl;
    }
}

Compilation message

jobs.cpp: In function 'bool ok(std::vector<std::pair<int, int> >&, int, int, int, bool)':
jobs.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (ptr >= x.size()) break;
      |             ~~~~^~~~~~~~~~~
jobs.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     return ptr >= x.size();
      |            ~~~~^~~~~~~~~~~
jobs.cpp: In function 'void setio(std::string)':
jobs.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((filename + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((filename + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2512 KB Output is correct
2 Correct 30 ms 2584 KB Output is correct
3 Correct 32 ms 2568 KB Output is correct
4 Correct 30 ms 2624 KB Output is correct
5 Correct 34 ms 2512 KB Output is correct
6 Correct 30 ms 2484 KB Output is correct
7 Correct 30 ms 2512 KB Output is correct
8 Correct 29 ms 2520 KB Output is correct
9 Incorrect 145 ms 4680 KB Output isn't correct
10 Incorrect 151 ms 4804 KB Output isn't correct
11 Incorrect 27 ms 2128 KB Output isn't correct
12 Incorrect 53 ms 4032 KB Output isn't correct
13 Incorrect 79 ms 6648 KB Output isn't correct
14 Incorrect 132 ms 8704 KB Output isn't correct
15 Incorrect 134 ms 10244 KB Output isn't correct
16 Incorrect 184 ms 12812 KB Output isn't correct
17 Incorrect 211 ms 15276 KB Output isn't correct
18 Incorrect 233 ms 16468 KB Output isn't correct
19 Incorrect 377 ms 20260 KB Output isn't correct
20 Incorrect 208 ms 15344 KB Output isn't correct