Submission #448060

# Submission time Handle Problem Language Result Execution time Memory
448060 2021-07-28T16:56:23 Z MohamedFaresNebili Job Scheduling (CEOI12_jobs) C++14
4 / 100
1000 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

using ll  = long long;
using ull = unsigned long long;
using ld  = long double;
using db  = double;
using ii  = pair<int, int>;
using iii = pair<ii, int>;
using pl  = pair<ll, ll>;
using ti  = tuple<int, int, int>;
using tll = tuple<ll, ll, ll>;
using tld = tuple<ld, ld, ld>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vc  = vector<char>;
using vs  = vector<string>;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define ppf pop_front
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((int)v.size())
#define all(x) (x).begin() , (x).end()
#define mt make_tuple
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define parse(A, n) for ( ll K = 0; K < n; K++) { cin >> A[K]; }
#define process(A, n) for( ll K = 1; K <= n; K++) { cin >> A[K]; }
#define out(A, n) { for ( ll K = 0; K < n; K++) { cout <<(K!=0?" ":"")<<A[K]; } cout<<'\n'; }
#define show(x) { bool first=true; for(auto& a:x) { if(first) { first=false; } else { cout<<" "; } cout<<a; } cout<<'\n'; }
#define mem1(memo) memset(memo, -1, sizeof memo);
#define mem0(memo) memset(memo, 0, sizeof(memo);
#define print(k) printf("%.2lf\n", k)

ld dist(ld x, ld y, ld a, ld b)    { return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
ll gcd(ll a , ll b){ return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b){ return (a * b) / gcd(a , b);}
ll fact(ll n) { return n > 1?(n * fact(n-1)):1;}

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void IO(string s = "") { if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } }

const int N = 100024;
const int M = 1e6+24;
const int inf = 1e9;
const int MOD = 1e9+7;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //East, West, South, North
const int dr[8] = {1,1,0,-1,-1,-1, 0, 1}, dc[8] = {0,1,1, 1, 0,-1,-1,-1};  // S,SE,E,NE,N,NW,W,SW
const long long INF = 1e18;
const double EPS = 1e-9;
const double PI = 3.14159265358979323846;

/** |||||||||||||||||||||||||||||||| SOLUTION |||||||||||||||||||||||||||||||| **/

vl sol[N];
bool can(ll val, ll n, ll d, ll m, vl& a, vector<vl>& b)
{
    vl s(n+2, 0); vl p[n+2], days[n+2];
    for(ll l=1;l<=n;l++) {
        s[l]=s[l-1]+a[l];
        for(auto u:b[l]) days[l].pb(u);
    }
    for(ll l=1;l<=n;l++) {
        ll diff=max(0LL, s[l]-val);
        ll k=s[l]/val; k+=(s[l]%val?1:0);
        if(k>d) return false;
        s[l+1]+=diff;
        for(ll i=0;i<val&&i<sz(days[l]); i++)
            p[l].pb(days[l][i]);
        for(ll i=val;i<sz(days[l]);i++) days[l+1].pb(days[l][i]);
    }
    for(ll l=1;l<=n;l++) sol[l]=p[l];
    return true;
}

void solve()
{
    /// JUST KEEP GOING
    ll n, d, m; cin>>n>>d>>m; vl a(n+1); vector<vl> b(n+2);
    for(ll l=0;l<m;l++) {
        ll k; cin>>k; b[k].pb(l+1); a[k]++; a[k+1]--;
    }
    ll lo=0, hi=LONG_LONG_MAX, ans;
    while(lo<=hi) {
        ll mid=(lo+hi)/2;
        if(can(mid, n, d, m, a,b)) { ans=mid; hi=mid-1; }
        else lo=mid+1;
    }
    cout<<ans<<'\n';
    for(ll l=1;l<=n;l++) {
        for(auto u:sol[l]) cout<<u<<" ";
        cout<<0<<'\n';
    }
}

int32_t main()
{

    FAST; /// IO("outofplace");
    int t; t=1;
    while(t--)
    {
        solve();
    }
    return 0;

}

/*** Stuff you should look for :
   * int overflow, array bounds.
   * special cases (n=1?).
   * Observe The Constraints.
   * do smth instead of nothing and stay organized.
   * Reformulate The Problem Into Something More Theoretical.
   * Use flush operator when having TLE.
   * WRITE STUFF DOWN.
   * DON'T GET STUCK ON ONE APPROACH.
    Think of:
   * Brute force, Greedy(High->Low), Dynamic Programming, Divide and Conquer.
   * BFS, DFS, Flood Fill, Topological Sort, Bipartite Check, Articulation Points, SCC.
   * Minimum, Maximum Spanning Tree, SSSP, All-Pairs Shortest Paths, Network Flow.
   * Disjoint Set Union, Segment tree, Math, Two Pointers, Strings.
    Motivation :
   * Change Your Approach.
   * Don't Spend Too Much Time On The Problem: Move On!
   * If You Don't Fight You Cannot Win.
***/

Compilation message

jobs.cpp: In function 'void setIn(std::string)':
jobs.cpp:48:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
jobs.cpp: In function 'void setOut(std::string)':
jobs.cpp:49:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 | void setOut(string s) { freopen(s.c_str(),"w",stdout); }
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 8064 KB Output isn't correct
2 Incorrect 131 ms 8040 KB Output isn't correct
3 Incorrect 132 ms 8116 KB Output isn't correct
4 Incorrect 160 ms 8096 KB Output isn't correct
5 Incorrect 132 ms 8056 KB Output isn't correct
6 Incorrect 128 ms 8028 KB Output isn't correct
7 Incorrect 132 ms 8040 KB Output isn't correct
8 Incorrect 145 ms 8052 KB Output isn't correct
9 Incorrect 221 ms 16296 KB Output isn't correct
10 Incorrect 225 ms 17196 KB Output isn't correct
11 Partially correct 126 ms 11312 KB Partially correct
12 Runtime error 271 ms 65540 KB Execution killed with signal 9
13 Partially correct 387 ms 31480 KB Partially correct
14 Runtime error 692 ms 65540 KB Execution killed with signal 9
15 Incorrect 511 ms 26436 KB Output isn't correct
16 Execution timed out 1093 ms 36548 KB Time limit exceeded
17 Execution timed out 1091 ms 36656 KB Time limit exceeded
18 Runtime error 737 ms 65540 KB Execution killed with signal 9
19 Execution timed out 1035 ms 64920 KB Time limit exceeded
20 Execution timed out 1088 ms 36740 KB Time limit exceeded