제출 #727557

#제출 시각아이디문제언어결과실행 시간메모리
727557bufferingJob Scheduling (CEOI12_jobs)C++17
60 / 100
550 ms31312 KiB
#include <bits/stdc++.h> using namespace std; void IO(string s = "") { if (s == "") { freopen("input.txt", "r", stdin); freopen("output 2.txt", "w", stdout); } if (s != "") { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } bool check(vector<pair<long long, long long>>& req, int machines, long long d, long long n, bool print) { if (machines < 1) return false; if (n * machines < req.size()) return false; vector<vector<long long>> days; for (int i = 0; i < n; i++) { days.push_back({}); } long long delay = 0; long long day = 1; long long i = 0; while (i < req.size() && day < n) { if (days[day - 1].size() == machines || req[i].first > day) { day++; if (day == n) break; } days[day - 1].push_back(req[i].second); delay = max(delay, abs(req[i].first - day)); i++; } if (delay > d) return false; if (print) { for (auto v: days) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << 0 << endl; } } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); //IO(); long long n; long long d; long long m; cin >> n >> d >> m; vector<pair<long long, long long>> req(m); for (int i = 0; i < m; i++) { cin >> req[i].first; req[i].second = i + 1; } sort(req.begin(), req.end()); long long lo = 1; long long hi = 1e5; bool w = false; while (lo <= hi) { long long mid = (lo + hi)/2; if (check(req, mid, d, n, 0)) { if (!check(req, mid - 1, d, n, 0)) { cout << mid << endl; check(req, mid, d, n, 1); w = true; break; } else hi = mid - 1; } else lo = mid + 1; } assert(w); }

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'bool check(std::vector<std::pair<long long int, long long int> >&, int, long long int, long long int, bool)':
jobs.cpp:19:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     if (n * machines < req.size()) return false;
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~
jobs.cpp:30:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (i < req.size() && day < n) {
      |            ~~^~~~~~~~~~~~
jobs.cpp:31:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |         if (days[day - 1].size() == machines || req[i].first > day) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
jobs.cpp:42:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for (int i = 0; i < v.size(); i++) {
      |                             ~~^~~~~~~~~~
jobs.cpp: In function 'void IO(std::string)':
jobs.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...