제출 #1123052

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

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;




void solve()
{
    int n,d,m; cin >> n >> d >> m;

    vector< vector<int> > cnt(n+1, vector<int>());
    FOR(i, 1, m){
        int x; cin >> x;
        cnt[x].push_back(i);
    }


    vector< vector<int> > task(n+1, vector<int>());
    auto good = [&](int machine) -> bool{
        queue< pair<int,int> > pq;
        FOR(i, 1, n){
            int remMac = machine; task[i].clear();

            for(int newTask : cnt[i]){
                pq.push(make_pair(-(i + d), newTask));
            }

            while(remMac > 0 && !pq.empty()){
                pair<int,int> e = pq.front(); pq.pop();

                int dead_time = -e.first;
                if(dead_time < i){
                    return false;
                }
                else{
                    remMac--;
                    task[i].push_back(e.second);
                }
            }
        }
        return true;
    };

    int l = 0, r = m+1;
    while(l+1 < r){
        int m = l+r>>1;
        if(good(m)){
            r = m;
        }
        else l = m;
    }

    cout << r <<"\n";

    FOR(i, 1, n){
        for(int v : task[i]){
            cout << v <<" ";
        } cout << "0\n";
    }
    return;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

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

jobs.cpp: In function 'int main()':
jobs.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...