답안 #416744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416744 2021-06-02T21:27:36 Z winstonyin Job Scheduling (CEOI12_jobs) C++11
15 / 100
471 ms 20700 KB
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <map>
#include <set>
#include <fstream>
#include <unordered_map>
#include <queue>
using namespace std;
using pi = pair<int, int>;
using pd = pair<double, double>; 
#define ll long long
#define all(x) (x).begin(), (x).end()
ll  days, delay, requests;
vector<pair<ll,ll>> seq;
bool works(ll  machines) {
    if(days*machines < requests) {
        return false;
    }
    ll  cur_day = 0; ll  cur_req = 0;
    while(cur_day < days && cur_req < requests) {
        for(ll  j = 0; j < machines; j++) {
            if(cur_req == requests) {
                break;
            }
            if(seq[cur_req].first <= cur_day+1) {
                if(cur_day+1 - seq[cur_req].first <= delay) {
                    cur_req++;
                }
                else {
                    return false;
                }
            }
            else {
                break;
            }
        }
        cur_day++;
    }
    return cur_req == requests;
}
bool p_works(ll  machines) {
    if(days*machines < requests) {
        return false;
    }
    ll  cur_day = 0; ll  cur_req = 0;
    while(cur_day < days && cur_req < requests) {
        for(ll  j = 0; j < machines; j++) {
            if(cur_req == requests) {
                break;
            }
            if(seq[cur_req].first <= cur_day+1) {
                if(cur_day+1 - seq[cur_req].first <= delay) {
                    cout << seq[cur_req].second << " ";
                    cur_req++;
                }
                else {
                    return false;
                }
            }
            else {
                break;
            }
        }
        cout << 0 << endl;
        cur_day++;
    }
    return cur_req == requests;
}
int  main() {
    cin >> days >> delay >> requests;
    for(ll  i = 0; i < requests; i++) {
        ll  day; cin >> day;
        seq.push_back({day, i+1});
    }
    sort(all(seq));
    ll  a = 1, b = 1e9;
    ll  ans;
    while(a <= b) {
        ll  mid = (a+b)/2;
        // cout << a << " " << b << endl;
        if(works(mid)) {
            ans = mid;
            b = mid-1;
        }
        else {
            a = mid+1;
        }
    }
    cout << ans << endl;
    p_works(ans);
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:96:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |     p_works(ans);
      |     ~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 2480 KB Unexpected end of file - int32 expected
2 Incorrect 40 ms 2480 KB Unexpected end of file - int32 expected
3 Incorrect 39 ms 2484 KB Unexpected end of file - int32 expected
4 Incorrect 40 ms 2560 KB Unexpected end of file - int32 expected
5 Incorrect 44 ms 2584 KB Unexpected end of file - int32 expected
6 Incorrect 40 ms 2508 KB Unexpected end of file - int32 expected
7 Incorrect 39 ms 2484 KB Unexpected end of file - int32 expected
8 Incorrect 39 ms 2472 KB Unexpected end of file - int32 expected
9 Incorrect 45 ms 2496 KB Unexpected end of file - int32 expected
10 Incorrect 45 ms 2484 KB Unexpected end of file - int32 expected
11 Incorrect 51 ms 2484 KB Unexpected end of file - int32 expected
12 Correct 101 ms 4736 KB Output is correct
13 Incorrect 154 ms 8600 KB Unexpected end of file - int32 expected
14 Correct 237 ms 9348 KB Output is correct
15 Correct 258 ms 11620 KB Output is correct
16 Incorrect 352 ms 16864 KB Unexpected end of file - int32 expected
17 Incorrect 413 ms 16744 KB Unexpected end of file - int32 expected
18 Incorrect 420 ms 18384 KB Unexpected end of file - int32 expected
19 Incorrect 471 ms 20700 KB Unexpected end of file - int32 expected
20 Incorrect 405 ms 16796 KB Unexpected end of file - int32 expected