Submission #649521

# Submission time Handle Problem Language Result Execution time Memory
649521 2022-10-10T11:29:24 Z ShirleyM Job Scheduling (CEOI12_jobs) C++14
0 / 100
105 ms 19660 KB
#include <bits/stdc++.h>
using namespace std;
//#define int int64_t
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1; i>=s;i--)
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()
#define fast {ios_base::sync_with_stdio(0); cin.tie(0);}

const int inf = 1e18;
const int INF = 1e9;

int n, d, m;
vi tasks;
vvi starts_in, ends_in;
vvi t_per_day;

bool ok(long long k){
    loop(i,1,n+1) t_per_day[i].clear();
    vi cur_tasks;
    vb vis(m);
    int cnt=0, done=0, closed=0;
    loop(i,1,n+1){
        cnt+=starts_in[i].size();
        done+=k;
        if(done > cnt) done=cnt;
        closed += ends_in[i].size();
        if(done < closed) return 0;
    }
    return 1;
}

int32_t main()
{
    fast;
    cin >> n >> d >> m;
    starts_in.resize(n+1);
    ends_in.resize(n+1);
    tasks.resize(m);
    t_per_day.resize(n+1);
    loop(i,0,m){
        cin >> tasks[i];
        int s=tasks[i], e=s+d;
        starts_in[s].pb(i);
        ends_in[e].pb(i);
    }

    long long l=0, r=m, mid, ans=-1;
    while(l<=r){
        mid = (l+r)/2;
        if(ok(mid)){
            ans = mid; r = mid-1;
        }
        else l = mid+1;
    }
    /*deque<int> cur_tasks;
    loop(i,1,n+1){
       for(int t:starts_in[i]){
            cur_tasks.pb(t);
       }
       loop(j,0,ans){
           t_per_day[i].pb(cur_tasks.front());
           cur_tasks.pop_front();
       }
    }*/
    cout << ans;
    /*loop(i,1,n+1){
        for(int t:t_per_day[i]) cout << t<< " ";
        cout << "0\n";
    }*/
    return 0;
}

Compilation message

jobs.cpp:21:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   21 | const int inf = 1e18;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2384 KB Unexpected end of file - int32 expected
2 Incorrect 8 ms 2396 KB Unexpected end of file - int32 expected
3 Incorrect 8 ms 2384 KB Unexpected end of file - int32 expected
4 Incorrect 8 ms 2384 KB Unexpected end of file - int32 expected
5 Incorrect 8 ms 2384 KB Unexpected end of file - int32 expected
6 Incorrect 8 ms 2384 KB Unexpected end of file - int32 expected
7 Incorrect 7 ms 2384 KB Unexpected end of file - int32 expected
8 Incorrect 8 ms 2384 KB Unexpected end of file - int32 expected
9 Incorrect 14 ms 8884 KB Unexpected end of file - int32 expected
10 Incorrect 14 ms 9044 KB Unexpected end of file - int32 expected
11 Incorrect 9 ms 1876 KB Unexpected end of file - int32 expected
12 Incorrect 17 ms 3228 KB Unexpected end of file - int32 expected
13 Incorrect 28 ms 5972 KB Unexpected end of file - int32 expected
14 Incorrect 59 ms 7728 KB Unexpected end of file - int32 expected
15 Incorrect 43 ms 8192 KB Unexpected end of file - int32 expected
16 Incorrect 105 ms 11064 KB Unexpected end of file - int32 expected
17 Incorrect 99 ms 13948 KB Unexpected end of file - int32 expected
18 Incorrect 72 ms 13000 KB Unexpected end of file - int32 expected
19 Incorrect 90 ms 19660 KB Unexpected end of file - int32 expected
20 Incorrect 92 ms 13932 KB Unexpected end of file - int32 expected