Submission #465151

#TimeUsernameProblemLanguageResultExecution timeMemory
465151tphuc2908Job Scheduling (CEOI12_jobs)C++14
100 / 100
391 ms13780 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i, x, y) for(int i = x; i <= y; ++i) #define repi(i,x,y) for(int i = x; i >= y; --i) #define ci(x) int x; cin>> x #define TC(t) ci(t); while(t--) #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define cii(x, y) ci(x); ci(y) typedef long long ll; typedef vector<int> vi; const int N = 1e6 + 5; const int mod = 1e9+7; const int inf = 1e9 + 5; void readfile(){ #ifdef ONLINE_JUDGE #else freopen("text.inp", "r", stdin); #endif // ONLINE_JUDGE // freopen("angry.in", "r", stdin); // freopen("angry.out", "w", stdout); } int n, d, m; pair<int,int> a[N]; void inp(){ cin >> n >> d >> m; rep(i,1,m){ cin >> a[i].fi; a[i].se = i; } sort(a + 1, a + m + 1); } bool check(int x){ int j = 1; queue<pair<int,int> > q; rep(i,1,n){ while(j <= m && a[j].fi==i){ q.push(a[j]); ++j; } int cnt = 0; while(cnt < x && !q.empty()){ if(i - q.front().fi > d) return 0; q.pop(); ++cnt; } } return q.empty(); } void process(){ int l = 1, r = m, res; while(l <= r){ ll mid = (l + r) >> 1; if(check(mid)){ res = mid; r = mid - 1; } else l = mid + 1; } cout << res << '\n'; queue<pair<int,int> > q; int j = 1; rep(i,1,n){ while(j <= m && a[j].fi==i){ q.push(a[j]); ++j; } int cnt = 0; while(cnt < res && !q.empty()){ cout << q.front().se << ' '; q.pop(); ++cnt; } cout << 0 << '\n'; } } int main(){ // readfile(); ios_base::sync_with_stdio(0); cin.tie(0); inp(); process(); return 0; }

Compilation message (stderr)

jobs.cpp: In function 'void readfile()':
jobs.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp: In function 'void process()':
jobs.cpp:78:25: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |         while(cnt < res && !q.empty()){
      |               ~~~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...