Submission #860695

# Submission time Handle Problem Language Result Execution time Memory
860695 2023-10-13T20:07:59 Z coldy Job Scheduling (CEOI12_jobs) C++14
100 / 100
359 ms 20292 KB
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
vector <int> p[(int)1e5 + 1], ans[(int)1e5 + 1];
bool ok(int x){
    for(int i = 1; i <= n; i++) ans[i].clear();
    for(int i = 1, idx = 1 ; i <= n; idx = max(idx, ++i)){
        for(int id: p[i]){
            if(ans[idx].size() == x) idx++;
            if(idx > i + d) return 0;
            ans[idx].push_back(id);
        }
    }
    return 1;
}
int main(){
    cin>>n>>d>>m;
 
    for(int i = 0; i < m; i++){
        int x;
        cin>>x;
        p[x].push_back(i + 1);
    }
 
    int lo = 1;
    int hi = m;
    while(lo < hi){
        int mid = (lo + hi)/2;
        if(ok(mid)) hi = mid;
        else lo = mid + 1;
    }
    ok(lo);
	cout<<lo<<endl;
    for(int i = 1; i <= n; i++){
        for(int id: ans[i]){
            cout<<id<<" ";
        }
        cout<<0<<"\n";
    }
}

Compilation message

jobs.cpp: In function 'bool ok(int)':
jobs.cpp:10:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   10 |             if(ans[idx].size() == x) idx++;
      |                ~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 6604 KB Output is correct
2 Correct 35 ms 6596 KB Output is correct
3 Correct 35 ms 6608 KB Output is correct
4 Correct 35 ms 6608 KB Output is correct
5 Correct 37 ms 6764 KB Output is correct
6 Correct 35 ms 6604 KB Output is correct
7 Correct 35 ms 6700 KB Output is correct
8 Correct 36 ms 6564 KB Output is correct
9 Correct 41 ms 6812 KB Output is correct
10 Correct 48 ms 7008 KB Output is correct
11 Correct 45 ms 6740 KB Output is correct
12 Correct 83 ms 8368 KB Output is correct
13 Correct 115 ms 11344 KB Output is correct
14 Correct 169 ms 13136 KB Output is correct
15 Correct 193 ms 14024 KB Output is correct
16 Correct 243 ms 16724 KB Output is correct
17 Correct 290 ms 20204 KB Output is correct
18 Correct 316 ms 19280 KB Output is correct
19 Correct 359 ms 19928 KB Output is correct
20 Correct 292 ms 20292 KB Output is correct