Submission #481744

#TimeUsernameProblemLanguageResultExecution timeMemory
481744mehdi_farhadianJob Scheduling (CEOI12_jobs)C++14
100 / 100
339 ms13764 KiB
#include <bits/stdc++.h> #define pb push_back #define endl '\n' #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("O0") #pragma GCC optimize("O1") using namespace std; typedef long long ll; const int N = 1e6 + 10; int n, d, m; vector<pair<int, int>> vec; bool check(int x) { queue<int> q; int last = 0; for (int i = 1; i <= n; i++) { while (last < vec.size() && vec[last].first == i) { q.push(i); last++; } int cnt = 0; while (q.size() && cnt < x) { cnt++; int tmp = q.front(); if (i - tmp > d) { return false; } q.pop(); } } return q.size() == 0; } void print(int x) { int ind = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < x && ind < vec.size(); j++) { cout << vec[ind].second << " "; ind++; } cout << 0 << endl; } } void solve() { int l = -1, r = 1e6; while (l + 1 < r) { int m = (l + r) / 2; if (check(m)) { r = m; } else { l = m; } } cout << r << endl; print(r); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> d >> m; vec.resize(m); for (int i = 0; i < m; i++) { cin >> vec[i].first; vec[i].second = i + 1; } sort(vec.begin(), vec.end()); solve(); }

Compilation message (stderr)

jobs.cpp: In function 'bool check(int)':
jobs.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         while (last < vec.size() && vec[last].first == i) {
      |                ~~~~~^~~~~~~~~~~~
jobs.cpp: In function 'void print(int)':
jobs.cpp:41:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int j = 0; j < x && ind < vec.size(); j++) {
      |                                  ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...