Submission #948291

# Submission time Handle Problem Language Result Execution time Memory
948291 2024-03-18T03:41:28 Z quanlt206 Job Scheduling (IOI19_job) C++17
24 / 100
102 ms 21424 KB
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;

template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }
template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */

const int N = 2e5 + 7;

int p[N], u[N], d[N], n;

bool checkSub1() {
    REP(i, 1, n)
        if (p[i] != i - 1) return false;
    return true;
}
namespace sub1 {
    ll Process() {
        ll res = 0, sum_t = 0;
        REP(i, 0, n) {
            sum_t+=d[i];
            res+=1LL * u[i] * sum_t;
        }
        return res;
    }
}

bool checkSub3() {
    REP(i, 1, n)
        if (p[i] != 0) return false;
    return true;
}

namespace sub3 {
    ll Process() {
        vector<int> node;
        ll res = 0, sum_t = 0;
        sum_t+=d[0];
        res+=sum_t * u[0];
        REP(i, 1, n)
            if (u[i] > 0) node.push_back(i);
        sort(all(node), [=](int x, int y){
             return (ld)d[x] / u[x] < (ld)d[y] / u[y];
        });
        for (auto x : node) {
            sum_t+=d[x];
            res+=sum_t * u[x];
        }
        return res;
    }
}


namespace sub4 {
    vector<int> v[N];
    ll Process() {
        ll res = 0, sum_u = 0;
        REP(i, 0, n) sum_u+=u[i];
        vector<int> node;
        REP(i, 1, n) v[p[i]].push_back(i);
        int cntLoop = 0;
        node.push_back(0);
        while (cntLoop < n) {
            cntLoop++;
            ll Min = 1e18;
            int idx = -1;
            sort(all(node), [=](int x, int y){
                 return (ld)d[x] / u[x] < (ld)d[y] / u[y];
            });
            REP(i, 0, 1)
                if (minimize(Min, 1LL * d[node[i]] * sum_u)) idx = i;
            res+=Min;
            sum_u-=u[node[idx]];
//            cout<<node[idx]<<endl;
            vector<int> new_node;
            REP(i, 0, (int)node.size())
                if (i == idx) {
                    for (auto x : v[node[i]]) new_node.push_back(x);
                }
                else new_node.push_back(node[i]);
            node = new_node;
        }
        return res;
    }
}

int64_t scheduling_cost(vector<int> P, vector<int> U, vector<int> D) {
    n = P.size();
    REP(i, 0, n) {
        p[i] = P[i];
        u[i] = U[i];
        d[i] = D[i];
    }
    if (checkSub1()) {
        return sub1::Process();
    }
    if (checkSub3()) {
        return sub3::Process();
    }
    return sub4::Process();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 13 ms 8628 KB Output is correct
6 Correct 23 ms 10900 KB Output is correct
7 Correct 34 ms 13180 KB Output is correct
8 Correct 50 ms 15232 KB Output is correct
9 Correct 51 ms 15184 KB Output is correct
10 Correct 51 ms 15352 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 45 ms 15348 KB Output is correct
13 Correct 43 ms 15104 KB Output is correct
14 Correct 43 ms 15108 KB Output is correct
15 Correct 43 ms 15220 KB Output is correct
16 Correct 45 ms 15220 KB Output is correct
17 Correct 44 ms 15340 KB Output is correct
18 Correct 44 ms 15232 KB Output is correct
19 Correct 43 ms 15352 KB Output is correct
20 Correct 43 ms 15108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 85 ms 15084 KB Output is correct
5 Correct 77 ms 15052 KB Output is correct
6 Correct 82 ms 15048 KB Output is correct
7 Correct 78 ms 14864 KB Output is correct
8 Correct 78 ms 15048 KB Output is correct
9 Correct 80 ms 15052 KB Output is correct
10 Correct 80 ms 15052 KB Output is correct
11 Correct 78 ms 14960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 5 ms 7000 KB Output is correct
6 Correct 85 ms 15576 KB Output is correct
7 Correct 102 ms 15612 KB Output is correct
8 Correct 87 ms 15564 KB Output is correct
9 Correct 94 ms 15560 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 5 ms 7004 KB Output is correct
13 Correct 5 ms 7224 KB Output is correct
14 Correct 84 ms 15628 KB Output is correct
15 Correct 87 ms 15608 KB Output is correct
16 Correct 86 ms 15564 KB Output is correct
17 Correct 84 ms 15564 KB Output is correct
18 Correct 85 ms 15468 KB Output is correct
19 Correct 85 ms 15560 KB Output is correct
20 Correct 85 ms 15560 KB Output is correct
21 Correct 85 ms 15560 KB Output is correct
22 Correct 85 ms 15448 KB Output is correct
23 Correct 83 ms 15592 KB Output is correct
24 Correct 87 ms 15564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Incorrect 62 ms 21424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Incorrect 2 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 13 ms 8628 KB Output is correct
6 Correct 23 ms 10900 KB Output is correct
7 Correct 34 ms 13180 KB Output is correct
8 Correct 50 ms 15232 KB Output is correct
9 Correct 51 ms 15184 KB Output is correct
10 Correct 51 ms 15352 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 45 ms 15348 KB Output is correct
13 Correct 43 ms 15104 KB Output is correct
14 Correct 43 ms 15108 KB Output is correct
15 Correct 43 ms 15220 KB Output is correct
16 Correct 45 ms 15220 KB Output is correct
17 Correct 44 ms 15340 KB Output is correct
18 Correct 44 ms 15232 KB Output is correct
19 Correct 43 ms 15352 KB Output is correct
20 Correct 43 ms 15108 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 85 ms 15084 KB Output is correct
25 Correct 77 ms 15052 KB Output is correct
26 Correct 82 ms 15048 KB Output is correct
27 Correct 78 ms 14864 KB Output is correct
28 Correct 78 ms 15048 KB Output is correct
29 Correct 80 ms 15052 KB Output is correct
30 Correct 80 ms 15052 KB Output is correct
31 Correct 78 ms 14960 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 5 ms 7000 KB Output is correct
37 Correct 85 ms 15576 KB Output is correct
38 Correct 102 ms 15612 KB Output is correct
39 Correct 87 ms 15564 KB Output is correct
40 Correct 94 ms 15560 KB Output is correct
41 Correct 1 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 5 ms 7004 KB Output is correct
44 Correct 5 ms 7224 KB Output is correct
45 Correct 84 ms 15628 KB Output is correct
46 Correct 87 ms 15608 KB Output is correct
47 Correct 86 ms 15564 KB Output is correct
48 Correct 84 ms 15564 KB Output is correct
49 Correct 85 ms 15468 KB Output is correct
50 Correct 85 ms 15560 KB Output is correct
51 Correct 85 ms 15560 KB Output is correct
52 Correct 85 ms 15560 KB Output is correct
53 Correct 85 ms 15448 KB Output is correct
54 Correct 83 ms 15592 KB Output is correct
55 Correct 87 ms 15564 KB Output is correct
56 Correct 1 ms 6744 KB Output is correct
57 Incorrect 62 ms 21424 KB Output isn't correct
58 Halted 0 ms 0 KB -