Submission #404227

# Submission time Handle Problem Language Result Execution time Memory
404227 2021-05-14T01:18:50 Z jadDebugs Job Scheduling (CEOI12_jobs) C++14
0 / 100
39 ms 65540 KB
// Author : Jad Isaac
// ID: jadDebugs
// TASK: -----
// LANG: C++                 

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pii pair<int, int>

const int hi = 1e7;

int n, d, m;
vector<int> ans[hi];

bool works(int robots, vector<pii> jobs)
{
    for (int i = 0; i < n; i++)
        ans[i].clear();

    int endT[robots] = {0};
    int maxD = 0;

    for (int i = 0, cur = 0; i < m; i++, cur++) {
        if (cur == robots)
            cur = 0;
        // if our end time for this job is > than our start time for this job
        // there will be delay
        if (endT[cur] + 1 > jobs[i].f) {
            endT[cur]++;
            maxD = max(maxD, endT[cur] - jobs[i].f);
        }
        else
            endT[cur] = jobs[i].f;
        ans[endT[cur]].push_back(jobs[i].s);
    }
    return maxD <= d;
}

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    if ((int)(name).size()) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }   
}


int main()
{
    //setIO("");

    cin >> n >> d >> m;

    // first = day of req
    // second = id or req
    vector<pii> jobs(m);

    for (int i = 0; i < m; i++) {
        cin >> jobs[i].f;
        jobs[i].s = i+1;
    }
    sort(begin(jobs), end(jobs));
    int l = 0, r = m;

    while (l < r) {
        int mid = l + (r-l)/2;
        if (works(mid, jobs))
            r = mid;
        else
            l = mid+1;
    }
    cout << l << '\n';
    for (int i = 0; i < n; i++) {
        for (int x: ans[i])
            cout << x << ' ';
        cout << "0\n";
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 65540 KB Execution killed with signal 9
2 Runtime error 35 ms 65540 KB Execution killed with signal 9
3 Runtime error 34 ms 65540 KB Execution killed with signal 9
4 Runtime error 37 ms 65540 KB Execution killed with signal 9
5 Runtime error 34 ms 65540 KB Execution killed with signal 9
6 Runtime error 34 ms 65540 KB Execution killed with signal 9
7 Runtime error 36 ms 65540 KB Execution killed with signal 9
8 Runtime error 39 ms 65540 KB Execution killed with signal 9
9 Runtime error 36 ms 65540 KB Execution killed with signal 9
10 Runtime error 34 ms 65540 KB Execution killed with signal 9
11 Runtime error 32 ms 65540 KB Execution killed with signal 9
12 Runtime error 37 ms 65540 KB Execution killed with signal 9
13 Runtime error 38 ms 65540 KB Execution killed with signal 9
14 Runtime error 35 ms 65540 KB Execution killed with signal 9
15 Runtime error 36 ms 65540 KB Execution killed with signal 9
16 Runtime error 32 ms 65540 KB Execution killed with signal 9
17 Runtime error 34 ms 65540 KB Execution killed with signal 9
18 Runtime error 35 ms 65540 KB Execution killed with signal 9
19 Runtime error 35 ms 65540 KB Execution killed with signal 9
20 Runtime error 35 ms 65540 KB Execution killed with signal 9