Submission #465150

# Submission time Handle Problem Language Result Execution time Memory
465150 2021-08-15T09:11:21 Z tphuc2908 Job Scheduling (CEOI12_jobs) C++14
0 / 100
4 ms 384 KB
#include<bits/stdc++.h>

using namespace std;
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
typedef long long ll;
typedef vector<int> vi;
const int N = 1e6 + 5;
const int mod = 1e9+7;
const int inf = 1e9 + 5;

void readfile(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("text.inp", "r", stdin);
    #endif // ONLINE_JUDGE
//    freopen("angry.in", "r", stdin);
//    freopen("angry.out", "w", stdout);
}

int n, d, m;
pair<int,int> a[N];

void inp(){
    cin >> n >> d >> m;
    rep(i,1,m){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(a + 1, a + m + 1);
}

bool check(int x){
    int j = 1;
    queue<pair<int,int> > q;
    rep(i,1,n){
        while(j <= m && a[j].fi==i){
            q.push(a[j]);
            ++j;
        }
        int cnt = 0;
        while(cnt < x && !q.empty()){
            if(i - q.front().fi > d)
                return 0;
            q.pop();
            ++cnt;
        }
    }
    return q.empty();
}

void process(){
    int l = 1, r = m, res;
    while(l <= r){
        ll mid = (l + r) >> 1;
        if(check(mid)){
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << res << '\n';
    queue<pair<int,int> > q;
    int j = 1;
    rep(i,1,n){
        while(j <= m && a[j].fi==i){
            q.push(a[j]);
            ++j;
        }
        int cnt = 0;
        while(cnt < res && !q.empty()){
            cout << q.front().se << ' ';
            q.pop();
            ++cnt;
        }
        cout << 0 << '\n';
    }
}

int main(){
    readfile();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    inp();
    process();
    return 0;
}

Compilation message

jobs.cpp: In function 'void readfile()':
jobs.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp: In function 'void process()':
jobs.cpp:78:25: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |         while(cnt < res && !q.empty()){
      |               ~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 2 ms 332 KB Output isn't correct
3 Incorrect 2 ms 332 KB Output isn't correct
4 Incorrect 2 ms 332 KB Output isn't correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Incorrect 2 ms 332 KB Output isn't correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 332 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 2 ms 332 KB Output isn't correct
11 Incorrect 2 ms 332 KB Output isn't correct
12 Incorrect 2 ms 332 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 2 ms 332 KB Output isn't correct
15 Incorrect 3 ms 332 KB Output isn't correct
16 Incorrect 2 ms 332 KB Output isn't correct
17 Incorrect 4 ms 332 KB Output isn't correct
18 Incorrect 3 ms 332 KB Output isn't correct
19 Incorrect 2 ms 332 KB Output isn't correct
20 Incorrect 2 ms 332 KB Output isn't correct