답안 #1095777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095777 2024-10-03T07:17:54 Z Requiem Job Scheduling (IOI19_job) C++17
100 / 100
160 ms 68544 KB
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define inf 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "jobscheduling"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;

/**
Cho 1 cây n đỉnh:
Cv i có parent là pi.
Cv i hoàn thành ở thời gian i có cost là t * u[i].
Cv i có thời gian hoàn thành là di.

Sắp xếp các cv sao cho các công việc pi luôn đứng trước i (trừ thằng 1).

subtask 1: cây đường thẳng.
Thì ta làm tuần tự.

subtask 2: Không có quan hệ ràng buộc cha con và d[i] = 1.
sort theo độ quan trọng của nó.

subtask 3: Không có quan hệ ràng buộc cha và con.
sort các đỉnh theo di / ui tăng dần.
Ta chứng minh được rằng nếu nó độc lập thì cách trên là tối ưu.

subtask 4: cây đường thẳng nhưng đỉnh 0 không nằm ở đầu đoạn thẳng.
Khi ta lấy 0 thì nó sẽ tách thành 2 đoạn thẳng.
**/

const int MAXN = 3e5 + 9;
int n;

namespace subtask1{
    bool check(){
        return n <= 10;
    }

    int solve(vector<int> p, vector<int> u, vector<int> d){
        int permutation[12], position[12];
        iota(permutation + 0, permutation + n, 0);
        int res = inf;
        do{
            int cur = 0;
            int ti =0;
            FOR(i, 0, n - 1){
                position[permutation[i]] = i;
                cur += (ti += d[permutation[i]]) * u[permutation[i]];
            }

            bool kt = true;
            FOR(i, 1, n - 1){
                if (position[p[i]] > position[i]) kt = false;
            }
            if (kt) minimize(res, cur);

        } while(next_permutation(permutation, permutation + n));
        return res;
    }
}
namespace subtask6{
    bool check(){
        return true;
    }
    struct pii{
        ll d, u, id;
        pii(int _d = 0, int _u = 0, int _id = 0): d(_d), u(_u), id(_id){}
        friend inline pii operator + (const pii &a, const pii &b){
            return pii(a.d + b.d, a.u + b.u, a.id);
        }

        friend inline pii operator - (const pii &a, const pii &b){
            return pii(a.d - b.d, a.u - b.u, a.id);
        }

        friend inline bool operator < (const pii &a, const pii &b){
            return a.d * b.u < a.u * b.d;
        }

        friend inline bool operator > (const pii &a, const pii &b){
            return (!(a < b));
        }

    };


    priority_queue<pii, vector<pii>, greater<pii>> pq[MAXN];
    vector<int> g[MAXN];
    pii a[MAXN];

    void dfs(int u){
        for(int v: g[u]){
            dfs(v); pq[u].push(a[v]);
        }

        while(!pq[u].empty()){
            if (pq[u].top() < a[u]){
                a[u] = a[u] + pq[u].top();

                int id = pq[u].top().id;
                pq[u].pop();

//                printf("MERGE: %lld %lld %lld\n", a[id].d, a[id].u, u, a[u].d, a[u].u);

                if (pq[u].size() < pq[id].size()) swap(pq[u], pq[id]);
                while(!pq[id].empty()){
                    pq[u].push(pq[id].top());
                    pq[id].pop();
                }
            }
            else break;
        }
    }

    long long get(vector<int> p, vector<int> u, vector<int> d){
        FOR(i, 1, n - 1){
            g[p[i]].pb(i);
        }

        FOR(i, 0, n - 1){
            a[i] = pii(d[i], u[i], i);
        }

        dfs(0);

        ll res = 0, cur = 0;
        priority_queue<pii, vector<pii>, greater<pii>> q;
        q.push(a[0]);
        while(!q.empty()){
            int id = q.top().id;
            q.pop();
            res += (cur += d[id]) * u[id];
//            printf("%lld\n", id);

            for(int v: g[id]){
                q.push(a[v]);
            }
        }
        return res;
    }

}
//d[i] / u[i];

long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d){
    n = u.size();
//    if (subtask1::check()) return subtask1::solve(p, u, d);
    if (subtask6::check()) return subtask6::get(p, u, d);
    return 0;
}

Compilation message

job.cpp: In function 'int subtask1::solve(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:7:13: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    7 | #define inf 1e18
      |             ^~~~
job.cpp:56:19: note: in expansion of macro 'inf'
   56 |         int res = inf;
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 10 ms 23924 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 28 ms 34904 KB Output is correct
6 Correct 49 ms 46040 KB Output is correct
7 Correct 62 ms 57168 KB Output is correct
8 Correct 80 ms 68432 KB Output is correct
9 Correct 80 ms 68544 KB Output is correct
10 Correct 87 ms 68340 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 82 ms 68436 KB Output is correct
13 Correct 84 ms 68432 KB Output is correct
14 Correct 86 ms 68440 KB Output is correct
15 Correct 81 ms 68432 KB Output is correct
16 Correct 92 ms 68432 KB Output is correct
17 Correct 104 ms 68344 KB Output is correct
18 Correct 85 ms 68436 KB Output is correct
19 Correct 80 ms 68492 KB Output is correct
20 Correct 84 ms 68436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23692 KB Output is correct
3 Correct 9 ms 23900 KB Output is correct
4 Correct 101 ms 47292 KB Output is correct
5 Correct 97 ms 47288 KB Output is correct
6 Correct 97 ms 47292 KB Output is correct
7 Correct 100 ms 47296 KB Output is correct
8 Correct 98 ms 47292 KB Output is correct
9 Correct 97 ms 47288 KB Output is correct
10 Correct 99 ms 47292 KB Output is correct
11 Correct 103 ms 47288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23824 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 14 ms 25220 KB Output is correct
6 Correct 94 ms 47980 KB Output is correct
7 Correct 103 ms 47988 KB Output is correct
8 Correct 106 ms 48188 KB Output is correct
9 Correct 95 ms 48084 KB Output is correct
10 Correct 9 ms 23896 KB Output is correct
11 Correct 10 ms 23900 KB Output is correct
12 Correct 12 ms 25116 KB Output is correct
13 Correct 14 ms 25224 KB Output is correct
14 Correct 100 ms 47856 KB Output is correct
15 Correct 116 ms 47968 KB Output is correct
16 Correct 95 ms 47804 KB Output is correct
17 Correct 98 ms 47800 KB Output is correct
18 Correct 96 ms 48080 KB Output is correct
19 Correct 95 ms 47800 KB Output is correct
20 Correct 95 ms 47804 KB Output is correct
21 Correct 101 ms 47804 KB Output is correct
22 Correct 99 ms 47804 KB Output is correct
23 Correct 103 ms 47836 KB Output is correct
24 Correct 99 ms 47900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23880 KB Output is correct
2 Correct 85 ms 57404 KB Output is correct
3 Correct 101 ms 57424 KB Output is correct
4 Correct 102 ms 57608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23900 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 11 ms 23900 KB Output is correct
9 Correct 11 ms 23900 KB Output is correct
10 Correct 15 ms 23900 KB Output is correct
11 Correct 10 ms 23896 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 9 ms 23900 KB Output is correct
14 Correct 11 ms 23896 KB Output is correct
15 Correct 9 ms 23900 KB Output is correct
16 Correct 9 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 10 ms 23924 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 28 ms 34904 KB Output is correct
6 Correct 49 ms 46040 KB Output is correct
7 Correct 62 ms 57168 KB Output is correct
8 Correct 80 ms 68432 KB Output is correct
9 Correct 80 ms 68544 KB Output is correct
10 Correct 87 ms 68340 KB Output is correct
11 Correct 11 ms 23900 KB Output is correct
12 Correct 82 ms 68436 KB Output is correct
13 Correct 84 ms 68432 KB Output is correct
14 Correct 86 ms 68440 KB Output is correct
15 Correct 81 ms 68432 KB Output is correct
16 Correct 92 ms 68432 KB Output is correct
17 Correct 104 ms 68344 KB Output is correct
18 Correct 85 ms 68436 KB Output is correct
19 Correct 80 ms 68492 KB Output is correct
20 Correct 84 ms 68436 KB Output is correct
21 Correct 10 ms 23900 KB Output is correct
22 Correct 10 ms 23692 KB Output is correct
23 Correct 9 ms 23900 KB Output is correct
24 Correct 101 ms 47292 KB Output is correct
25 Correct 97 ms 47288 KB Output is correct
26 Correct 97 ms 47292 KB Output is correct
27 Correct 100 ms 47296 KB Output is correct
28 Correct 98 ms 47292 KB Output is correct
29 Correct 97 ms 47288 KB Output is correct
30 Correct 99 ms 47292 KB Output is correct
31 Correct 103 ms 47288 KB Output is correct
32 Correct 10 ms 23896 KB Output is correct
33 Correct 9 ms 23900 KB Output is correct
34 Correct 9 ms 23824 KB Output is correct
35 Correct 10 ms 23900 KB Output is correct
36 Correct 14 ms 25220 KB Output is correct
37 Correct 94 ms 47980 KB Output is correct
38 Correct 103 ms 47988 KB Output is correct
39 Correct 106 ms 48188 KB Output is correct
40 Correct 95 ms 48084 KB Output is correct
41 Correct 9 ms 23896 KB Output is correct
42 Correct 10 ms 23900 KB Output is correct
43 Correct 12 ms 25116 KB Output is correct
44 Correct 14 ms 25224 KB Output is correct
45 Correct 100 ms 47856 KB Output is correct
46 Correct 116 ms 47968 KB Output is correct
47 Correct 95 ms 47804 KB Output is correct
48 Correct 98 ms 47800 KB Output is correct
49 Correct 96 ms 48080 KB Output is correct
50 Correct 95 ms 47800 KB Output is correct
51 Correct 95 ms 47804 KB Output is correct
52 Correct 101 ms 47804 KB Output is correct
53 Correct 99 ms 47804 KB Output is correct
54 Correct 103 ms 47836 KB Output is correct
55 Correct 99 ms 47900 KB Output is correct
56 Correct 10 ms 23880 KB Output is correct
57 Correct 85 ms 57404 KB Output is correct
58 Correct 101 ms 57424 KB Output is correct
59 Correct 102 ms 57608 KB Output is correct
60 Correct 10 ms 23900 KB Output is correct
61 Correct 10 ms 23900 KB Output is correct
62 Correct 11 ms 23900 KB Output is correct
63 Correct 11 ms 23900 KB Output is correct
64 Correct 10 ms 23900 KB Output is correct
65 Correct 10 ms 23900 KB Output is correct
66 Correct 11 ms 23896 KB Output is correct
67 Correct 11 ms 23900 KB Output is correct
68 Correct 11 ms 23900 KB Output is correct
69 Correct 15 ms 23900 KB Output is correct
70 Correct 10 ms 23896 KB Output is correct
71 Correct 10 ms 23900 KB Output is correct
72 Correct 9 ms 23900 KB Output is correct
73 Correct 11 ms 23896 KB Output is correct
74 Correct 9 ms 23900 KB Output is correct
75 Correct 9 ms 23900 KB Output is correct
76 Correct 10 ms 23900 KB Output is correct
77 Correct 11 ms 23896 KB Output is correct
78 Correct 13 ms 23756 KB Output is correct
79 Correct 10 ms 23896 KB Output is correct
80 Correct 10 ms 23836 KB Output is correct
81 Correct 9 ms 23900 KB Output is correct
82 Correct 10 ms 23900 KB Output is correct
83 Correct 10 ms 23900 KB Output is correct
84 Correct 10 ms 23724 KB Output is correct
85 Correct 9 ms 23900 KB Output is correct
86 Correct 11 ms 23900 KB Output is correct
87 Correct 9 ms 23900 KB Output is correct
88 Correct 12 ms 24412 KB Output is correct
89 Correct 17 ms 24832 KB Output is correct
90 Correct 18 ms 24896 KB Output is correct
91 Correct 41 ms 29716 KB Output is correct
92 Correct 65 ms 35408 KB Output is correct
93 Correct 136 ms 46800 KB Output is correct
94 Correct 131 ms 46792 KB Output is correct
95 Correct 138 ms 47052 KB Output is correct
96 Correct 144 ms 46792 KB Output is correct
97 Correct 130 ms 46032 KB Output is correct
98 Correct 133 ms 45840 KB Output is correct
99 Correct 121 ms 45004 KB Output is correct
100 Correct 137 ms 46804 KB Output is correct
101 Correct 139 ms 48344 KB Output is correct
102 Correct 124 ms 44308 KB Output is correct
103 Correct 139 ms 45332 KB Output is correct
104 Correct 160 ms 45844 KB Output is correct
105 Correct 120 ms 46324 KB Output is correct
106 Correct 103 ms 43396 KB Output is correct