제출 #470959

#제출 시각아이디문제언어결과실행 시간메모리
470959XIIJob Scheduling (CEOI12_jobs)C++17
100 / 100
475 ms13764 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI12_jobs"
void Fi(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

int firstTrue(int lo, int hi, function<bool(int)> f){
    while(lo < hi){
        int mid = lo + (hi - lo) / 2;
        if(f(mid)) hi = mid;
        else lo = mid + 1;
    }
    return hi;
}

int main(){
    IOS;
    Fi();
    int n, d, m; cin >> n >> d >> m;
    vector<int> day(m);
    for(int &x: day) cin >> x;
    vector<int> pos(m); iota(ALL(pos), 0);
    sort(ALL(pos), [&](const int &i, const int &j){
            return day[i] < day[j];
        }
    );

    const auto check = [&](const int &x) -> bool{
        int i = 0;
        FORU(T, 1, n) FOR(j, 0, x) if(i < m && day[pos[i]] <= T){
            if(i < m && day[pos[i++]] + d < T) return false;
        } else break;
        return (i >= m);
    };

    int ans = firstTrue(m / n + (m % n ? 1 : 0), m, check);
    cout << ans << "\n";
    int i = 0;
    FORU(T, 1, n){
        FOR(j, 0, ans) if(i < m && day[pos[i]] <= T){
            if(i < m) cout << pos[i++] + 1 << " ";
        } else break;
        cout << "0\n";
    }
    return 0;
}

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

jobs.cpp: In function 'void Fi()':
jobs.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...