Submission #470934

#TimeUsernameProblemLanguageResultExecution timeMemory
470934XIIJob Scheduling (CEOI12_jobs)C++17
55 / 100
318 ms13764 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define mp make_pair #define eb emplace_back #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define FORU(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define IOS cin.tie(0)->sync_with_stdio(false); #define PROB "CEOI12_jobs" void Fi(){ if(fopen(PROB".inp", "r")){ freopen(PROB".inp", "r", stdin); freopen(PROB".out", "w", stdout); } } int firstTrue(int lo, int hi, function<bool(int)> f){ while(lo < hi){ int mid = lo + (hi - lo) / 2; if(f(mid)) hi = mid; else lo = mid + 1; } return hi; } int main(){ IOS; Fi(); int n, d, m; cin >> n >> d >> m; vector<int> day(m); for(int &x: day) cin >> x; vector<int> pos(m); iota(ALL(pos), 0); sort(ALL(pos), [&](const int &i, const int &j){ return day[i] < day[j]; } ); const auto check = [&](const int &x) -> bool{ // if(m % x && day[pos.back()] + d < m / x + 1) return false; // for(int i = x - 1, T = 1; i < m; i += x, ++T){ // if(day[pos[i]] + d <= T) return false; // } // return true; for(int i = 0, j = 0, T = 1; i < m; i = j, ++T){ if(T > n) return false; while(j < m && j - i < x) if(day[pos[j++]] + d < T) return false; } return true; }; int ans = firstTrue(m / n + (m % n ? 1 : 0), m, check); cout << ans << "\n"; for(int i = 0, j = 0, T = 1; T <= n; i = j, ++T){ while(j < m && j - i < ans) cout << pos[j++] + 1 << " "; cout << "0\n"; } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'void Fi()':
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(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...