답안 #400824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400824 2021-05-08T17:57:47 Z phisti Job Scheduling (CEOI12_jobs) C++17
0 / 100
605 ms 21292 KB
// The Central Engineering Organization,  International (CEOI) has received
// Mjob requests for the next Ndays. To perform a job requires exactly one day
// by one machine. CEOI has access to several machines, each of which can
// perform at most one job per day, sothe organization can do at most as many
// jobs a day as the number of available machines. CEOI aims to work with at
// mostDdays of delay, which means that if a client submits a job for
// processing on day S, then it will be finished no later than on day S+D.

// Task:
// You are to write a program that computes the minimum number of machines that
// the organization needs to process all jobs with at most Ddays of
// delay.
//
// Input
// The  first  line  of  the  input  contains  three  integers, N(1
// ≤N ≤100000)  is  the  number  of  days  the organization performs jobs, D(0
// ≤D< N) is the maximum number of days permitted for the delay, and M(1 ≤M ≤1
// 000 000) is the number of job requests. The days are numbered from 1to N,
// and the requests are numbered  from 1toM.  The  second  line  contains
// exactly Mintegers  separated  by  space,  the ith  number  is the day when
// request iis submitted for processing.No jobs are submitted after day
// N–D.
//
// Output
// The first line of the output contains one integer, the minimum
// number ofmachines that the organization needs  to  be  able  to  process
// all  jobs  with  at  most Ddays  of  delay.  The  next Nlines  describe  a
// feasible schedule  for  processing  the  requests.  The  (i+1)th  line
// contains  the  identifiers  of  the  requests  scheduled  for day i.
// Numbers  in  a  line  must  be  separated  by  space  and  terminated  by
// 0.  If  there  are  multiple  solutions, your program should output only
// one; it does not matter which one.
//
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <queue>

#define sz(x)   (int)size(x)
#define last_elem(coll) (*(coll.rbegin()))
#define FOR(x, e) for(u32 x = 0; x < (u32)(e); x++)
#define FORR(x, e) for(u32 x = (u32)(e) - 1; x < (u32)(e); x--)
#define FOB(x, b, e) for(auto x = (b); x != (e); x++)
#define FOI(x, e, i) for(u32 x = 0; x < (u32)e; x += (u32)(i))
#define FORE(x, C) for(auto& x: C)

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i16 = short;
using u16 = unsigned short;
using i8 = char;
using u8 = unsigned char;
using f64 = double;
using f32 = float;
using si = i32;
using sl = i64;
using ui = u32;
using ul = u64;
using vl = std::vector<i64>;
using vi = std::vector<i32>;
using vs = std::vector<i16>;
using vul = std::vector<u64>;
using vui = std::vector<u32>;
using vus = std::vector<u16>;

#ifdef MY_COMPILE
    auto stin = std::ifstream("TestSamples/Job_Scheduling_CEOI.in");
    auto sout = std::ofstream("TestSamples/Job_Scheduling_CEOI.out");
#elif OLDERN
    auto stin = std::ifstream("bcount.in");
    auto sout = std::ofstream("bcount.out");
#else
    auto &stin = std::cin;
    auto &sout = std::cout;
#endif

bool is_goodp(vector<pair<sl, sl>>& schedules, sl days, sl delay, sl n)
{
    sl jobs = 0;
    sl nth_day = 1;
    queue<sl> js;
    FOR(i, sz(schedules)) {
        if (!i || schedules[i].first != schedules[i - 1].first) {
            sl inc = 0;
            if (i) inc = schedules[i].first - schedules[i - 1].first;
            else inc = schedules[i].first - 1;
            FOR(k, inc) {
                FOR(j, n) {
                    if (!sz(js)) break;
                    sout << js.front() << ' ';
                    js.pop();
                }

                sout << "0" << endl;
                nth_day++;
            }
        }
        
        js.push(schedules[i].second);
    }
    
    while(nth_day <= days) {
        FOR(j, n) {
            if (!sz(js)) break;
            sout << js.front() << ' ';
            js.pop();
        }

        sout << "0" << endl;
        nth_day++;
    }

    return true;
}

bool is_good(vector<pair<sl, sl>>& schedules, sl days, sl delay, sl n)
{
    sl jobs = 0;
    sl nth_day = 1;
    FOR(i, sz(schedules)) {
        if (!i || schedules[i].first != schedules[i - 1].first) {
            auto inc = i?
                nth_day+= schedules[i].first - schedules[i - 1].first
                : nth_day += schedules[i].first - 1;
            
            jobs -= n * inc;
            jobs = max((sl)0, jobs);
            nth_day += inc;
        }
        
        jobs++;
        if (jobs / n > delay) {
            return false;
        }
    }
    
    if (jobs / n > (days - nth_day))
    
    return true;
}

int main()
{
    ui N, D, M;
    stin >> N >> D >> M;
    
    vector<pair<sl, sl>> schedules(M);
    FOR(i, M) {
        stin >> schedules[i].first;
        schedules[i].second = i + 1;
    }
    
    sort(schedules.begin(), schedules.end());

    sl in = 1, ax = M;
    while(in < ax) {
        auto ean = (in + ax) / 2;
        if (is_good(schedules, N, D, ean)) {
            ax = ean;
        } else {
            in = ean + 1;
        }
    }
    
    sout << in << endl;
    is_goodp(schedules, N, D, in);

    return 0;
}

Compilation message

jobs.cpp: In function 'bool is_goodp(std::vector<std::pair<long long int, long long int> >&, sl, sl, sl)':
jobs.cpp:86:8: warning: unused variable 'jobs' [-Wunused-variable]
   86 |     sl jobs = 0;
      |        ^~~~
jobs.cpp: In function 'bool is_good(std::vector<std::pair<long long int, long long int> >&, sl, sl, sl)':
jobs.cpp:147:1: warning: control reaches end of non-void function [-Wreturn-type]
  147 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 3520 KB Output isn't correct
2 Incorrect 62 ms 3396 KB Output isn't correct
3 Incorrect 62 ms 3396 KB Output isn't correct
4 Incorrect 66 ms 3492 KB Output isn't correct
5 Incorrect 62 ms 3504 KB Output isn't correct
6 Incorrect 63 ms 3444 KB Output isn't correct
7 Incorrect 62 ms 3480 KB Output isn't correct
8 Incorrect 62 ms 3476 KB Output isn't correct
9 Incorrect 204 ms 3268 KB Output isn't correct
10 Incorrect 207 ms 3396 KB Output isn't correct
11 Incorrect 51 ms 2616 KB Output isn't correct
12 Incorrect 100 ms 5120 KB Output isn't correct
13 Incorrect 151 ms 7332 KB Output isn't correct
14 Incorrect 229 ms 9748 KB Output isn't correct
15 Incorrect 248 ms 11908 KB Output isn't correct
16 Incorrect 339 ms 14292 KB Output isn't correct
17 Incorrect 390 ms 16452 KB Output isn't correct
18 Incorrect 423 ms 18816 KB Output isn't correct
19 Incorrect 605 ms 21292 KB Output isn't correct
20 Incorrect 393 ms 16480 KB Output isn't correct