Submission #727834

#TimeUsernameProblemLanguageResultExecution timeMemory
727834bufferingJob Scheduling (CEOI12_jobs)C++17
100 / 100
842 ms23596 KiB
#include <bits/stdc++.h>
using namespace std;
 
void IO(string s = "")
{
    if (s == "")
    {
        freopen("input.txt", "r", stdin);
        freopen("output 2.txt", "w", stdout);
    }
    if (s != "")
    {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}
bool check(vector<pair<int, int>>& req, int machines, int d, int n, bool print) {
    if (machines < 1) return false;
    vector<vector<int>> days;
    for (int i = 0; i < n; i++) {
        days.push_back({});
    }
    int delay = 0;
 
    int day = 1;
 
    int i = 0;
 
    while (i < req.size() && day < n) {
        if (days[day - 1].size() == machines) {
            day++;
            if (day == n) break;
        }
        if (req[i].first > day) {
            day = req[i].first;
        }
        days[day - 1].push_back(req[i].second);
        delay = max(delay, abs(req[i].first - day));
        i++;
    }
    if (delay > d) return false;
    if (print) {
        for (auto v: days) {
            for (int i = 0; i < v.size(); i++) {
                cout << v[i] << " ";
            }
            cout << 0 << endl;
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    //IO();
 
    int n; int d; int m;
    cin >> n >> d >> m;
 
    vector<pair<int, int>> req(m);
 
    for (int i = 0; i < m; i++) {
        cin >> req[i].first;
        req[i].second = i + 1;
    }
    sort(req.begin(), req.end());
 
    int lo = 1; int hi = 1e9;
 
    while (lo <= hi) {
        int mid = (lo + hi)/2;
        if (check(req, mid, d, n, 0)) {
            if (!check(req, mid - 1, d, n, 0)) {
                cout << mid << endl;
                check(req, mid, d, n, 1);
                break;
            }
            else hi = mid - 1;
        }
        else lo = mid + 1;
    }
 
 
 
}

Compilation message (stderr)

jobs.cpp: In function 'bool check(std::vector<std::pair<int, int> >&, int, int, int, bool)':
jobs.cpp:29:14: 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 |     while (i < req.size() && day < n) {
      |            ~~^~~~~~~~~~~~
jobs.cpp:30:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         if (days[day - 1].size() == machines) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
jobs.cpp:44:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             for (int i = 0; i < v.size(); i++) {
      |                             ~~^~~~~~~~~~
jobs.cpp: In function 'void IO(std::string)':
jobs.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...