Submission #623522

#TimeUsernameProblemLanguageResultExecution timeMemory
623522binisgiannisJob Scheduling (CEOI12_jobs)C++17
0 / 100
2 ms340 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> pi; #define x first #define y second int N, D, M; vector<pi> vec; bool f(int x) { int index = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < x; j++) { if (vec[index].x > (i+1)) break; if ((i+1) - vec[index].x > D) return false; index++; if (index >= M) goto endofloop; } } endofloop: return index >= M; } vector<vector<int>> res(int x) { vector<vector<int>> res(N, vector<int>(x, 0)); int index = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < x; j++) { res[i][j] = vec[index].y; index++; if (index >= M) goto endofloop; } } endofloop: return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); freopen("analyze.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> N >> D >> M; vec.resize(M); for (int i = 0; i < M; i++) { cin >> vec[i].x; vec[i].y = i+1; } sort(vec.begin(), vec.end()); int l = 1, r = M; while (l < r) { int mid = (l+r)/2; if (!f(mid)) l = mid+1; else { r = mid; } } vector<vector<int>> result = res(l); cout << l << '\n'; for (int i = 0; i < result.size(); i++) { for (int j = 0; j < result[i].size(); j++) { if (result[i][0] == 0) break; cout << result[i][j] << ' '; } cout << 0 << '\n'; } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = 0; i < result.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
jobs.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int j = 0; j < result[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
jobs.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("analyze.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...