Submission #439745

# Submission time Handle Problem Language Result Execution time Memory
439745 2021-06-30T18:47:40 Z xz56 Job Scheduling (CEOI12_jobs) C++17
58 / 100
540 ms 19148 KB
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define INF 1e18
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
// Author : Nav

int n,d,m;
vector<pair<int,int>> req;
vector<vector<int>> schedule;
bool check(int machines){
  schedule.clear();
  schedule.resize(n+1);
  int p = 0;
  for(int i = 1;i<=n;i++){
    while(schedule[i].size() < machines && req[p].fi<=i && p<m){
      schedule[i].pb(req[p].se);
      if(i - req[p].fi > d) return false;
      p++;
    }
    // schedule[i].pb(0);
  }
  return true;
}
int main() {
  cin >> n >> d >> m;
  for(int i = 0;i<m;i++){
    int x; cin >> x;
    req.pb({x,i+1});
  }
  sort(req.begin(),req.end());
  schedule.resize(n+1);
  int L = 1;
  int R = m;
  int ans = 0;
  while(L<=R){
    int mid = L + (R-L)/2;
    if(check(mid)){
      ans =mid;
      R = mid-1;
    }
    else {
      L = mid+1;
    }
  }
  cout << L << '\n';
  for(int i = 1;i<=n;i++){
    for(int x : schedule[i]){
      cout << x << " ";
    }
    cout << 0 << '\n';
  }
}

Compilation message

jobs.cpp: In function 'bool check(int)':
jobs.cpp:25:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while(schedule[i].size() < machines && req[p].fi<=i && p<m){
      |           ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
jobs.cpp: In function 'int main()':
jobs.cpp:44:7: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   44 |   int ans = 0;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Partially correct 50 ms 2440 KB Partially correct
2 Partially correct 46 ms 2476 KB Partially correct
3 Partially correct 46 ms 2472 KB Partially correct
4 Partially correct 46 ms 2452 KB Partially correct
5 Partially correct 46 ms 2476 KB Partially correct
6 Partially correct 47 ms 2540 KB Partially correct
7 Partially correct 47 ms 2436 KB Partially correct
8 Partially correct 46 ms 2492 KB Partially correct
9 Partially correct 68 ms 4652 KB Partially correct
10 Partially correct 69 ms 4736 KB Partially correct
11 Correct 59 ms 2100 KB Output is correct
12 Correct 123 ms 4224 KB Output is correct
13 Partially correct 178 ms 6608 KB Partially correct
14 Correct 277 ms 9008 KB Output is correct
15 Correct 293 ms 10324 KB Output is correct
16 Correct 414 ms 12676 KB Output is correct
17 Partially correct 486 ms 15900 KB Partially correct
18 Correct 525 ms 16388 KB Output is correct
19 Partially correct 540 ms 19148 KB Partially correct
20 Partially correct 528 ms 15916 KB Partially correct