Submission #553840

#TimeUsernameProblemLanguageResultExecution timeMemory
553840wyhong3103Job Scheduling (CEOI12_jobs)C++14
15 / 100
241 ms17200 KiB
#include <bits/stdc++.h> #include <limits> #define all(x) begin(x),end(x) #define fir first #define sec second #define sz(x) x.size() #define pb push_back using namespace std; using vi = vector<int>; using pi = pair<int,int>; using ll = long long; const double EPS = (1e-7); void setio(string s){ freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } bool valid(vector<pi>& a, int n, int d){ int day = 0; int cur = 0; for(auto& i : a){ if ((day-i.fir) > d){ return false; } cur++; if (cur == n){ cur = 0; day++; } } return true; } void solve(){ int n, d, m; cin >> n >> d >> m; vector<pi> a(m); for(int i{}; i < m; i++){ cin >> a[i].fir; a[i].sec = i+1; } sort(all(a)); int lo = 1, hi = m; while (hi > lo){ int mid = lo + (hi-lo)/2; if (valid(a, mid, d)){ hi = mid; }else{ lo = mid+1; } } cout << lo << '\n'; int p = 0; for(int i{}; i < n; i++){ for(int i{}; i < lo; i++){ if (p < sz(a)){ cout << a[p].sec << ' '; p++; }else break; } cout << 0 << '\n'; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

jobs.cpp: In function 'void solve()':
jobs.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             if (p < sz(a)){
      |                   ^
jobs.cpp: In function 'void setio(std::string)':
jobs.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  freopen((s + ".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:17:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  freopen((s + ".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...