답안 #866440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866440 2023-10-26T07:36:17 Z SorahISA Job Scheduling (IOI19_job) C++17
58 / 100
3000 ms 34128 KB
#include "job.h"
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;

struct Job {
    int64 u, d, id;
    Job(int64 _u, int64 _d, int64 _id) : u(_u), d(_d), id(_id) {}
    bool operator < (const Job &rhs) const {
        return d * rhs.u < rhs.d * u;
    }
};

int64 scheduling_cost(vector<int> p, vector<int> u, vector<int> d) {
    int N = p.size();
    vector<vector<int>> ch(N);
    for (int i = 1; i < N; ++i) ch[p[i]].emplace_back(i);
    
    multiset<Job> jobs;
    for (int i = 0; i < N; ++i) jobs.emplace(u[i], d[i], i);
    
    int64 tim = 0, ans = 0;
    while (jobs.size()) {
        
        Job job = *begin(jobs);
        jobs.erase(begin(jobs));
        
        // cerr << "(" << job.u << ", " << job.d << ", " << job.id << ")\n";
        if (u[job.id] != job.u or d[job.id] != job.d) continue;
        // cerr << "(" << job.u << ", " << job.d << ", " << job.id << ")\n";
        
        if (p[job.id] == -1) {
            ans += job.u * (tim += job.d);
            for (int x : ch[job.id]) p[x] = -1;
            ch[job.id].clear(), ch[job.id].shrink_to_fit();
        }
        else {
            ans -= u[p[job.id]] * job.d;
            int64 new_u = u[p[job.id]] + job.u;
            int64 new_d = d[p[job.id]] + job.d;
            
            // if (ch[p[job.id]].size() <= ch[job.id].size()) {
            //     for (int x : ch[p[job.id]]) {if (x != job.id) ch[job.id].emplace_back(x), p[x] = job.id;}
            //     ch[p[job.id]].clear(), ch[p[job.id]].shrink_to_fit();
            //     if (p[p[job.id]] != -1) *find(begin(ch[p[p[job.id]]]), end(ch[p[p[job.id]]]), p[job.id]) = job.id;
            //     p[job.id] = p[p[job.id]];
            //     jobs.emplace(u[job.id] = new_u, d[job.id] = new_d, job.id);
            // }
            // else {
                for (int x : ch[job.id]) ch[p[job.id]].emplace_back(x), p[x] = p[job.id];
                ch[job.id].clear(), ch[job.id].shrink_to_fit();
                jobs.emplace(u[p[job.id]] = new_u, d[p[job.id]] = new_d, p[job.id]);
            // }
        }
    }
    
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 69 ms 7744 KB Output is correct
6 Correct 204 ms 15692 KB Output is correct
7 Correct 434 ms 25336 KB Output is correct
8 Correct 873 ms 34128 KB Output is correct
9 Correct 535 ms 33064 KB Output is correct
10 Correct 616 ms 33956 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 473 ms 32964 KB Output is correct
13 Execution timed out 3039 ms 32348 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 163 ms 23064 KB Output is correct
5 Correct 122 ms 23112 KB Output is correct
6 Correct 117 ms 22960 KB Output is correct
7 Correct 127 ms 22932 KB Output is correct
8 Correct 136 ms 23116 KB Output is correct
9 Correct 135 ms 23072 KB Output is correct
10 Correct 122 ms 22984 KB Output is correct
11 Correct 135 ms 22980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 125 ms 23364 KB Output is correct
7 Correct 141 ms 22980 KB Output is correct
8 Correct 109 ms 22984 KB Output is correct
9 Correct 127 ms 22984 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 121 ms 23108 KB Output is correct
15 Correct 121 ms 23112 KB Output is correct
16 Correct 121 ms 23100 KB Output is correct
17 Correct 130 ms 23096 KB Output is correct
18 Correct 126 ms 22984 KB Output is correct
19 Correct 119 ms 22984 KB Output is correct
20 Correct 143 ms 22984 KB Output is correct
21 Correct 114 ms 23100 KB Output is correct
22 Correct 115 ms 22968 KB Output is correct
23 Correct 140 ms 22980 KB Output is correct
24 Correct 119 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 524 ms 29976 KB Output is correct
3 Correct 685 ms 33624 KB Output is correct
4 Correct 490 ms 32940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 544 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 69 ms 7744 KB Output is correct
6 Correct 204 ms 15692 KB Output is correct
7 Correct 434 ms 25336 KB Output is correct
8 Correct 873 ms 34128 KB Output is correct
9 Correct 535 ms 33064 KB Output is correct
10 Correct 616 ms 33956 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 473 ms 32964 KB Output is correct
13 Execution timed out 3039 ms 32348 KB Time limit exceeded
14 Halted 0 ms 0 KB -