답안 #906320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906320 2024-01-14T01:09:10 Z vjudge1 Job Scheduling (IOI19_job) C++17
5 / 100
69 ms 16112 KB
#include "job.h"
#include <vector>

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

#define NN
#define M 1000000007 // 998244353

vl adj[200010];

long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
    ll ans = 0;
    int n = (int)p.size();
    bool case1 = true,case2 = true;

    for(int i=1;i<n;i++){
        case1 &= p[i]==i-1;

        case2 &= p[i]==0;
        case2 &= d[i]==1;

        adj[p[i]].push_back(i);
    }

    if(case1){
        ll time = 0;
        for(int i=0;i<n;i++){
            time += d[i];
            ans += time*u[i];
        }
        return ans;
    }

    if (n <= 200) {
        ll ans = 0;
        auto cmp = [&](int i,int j){
            return -u[i]*d[j] < -u[j]*d[i];
        };
        auto dfs = [&](auto &&self, ll i) -> vl {
            vector<vl> ord;
            for (auto x: adj[i]) ord.push_back(self(self, x));
            vl ans;
            while (ord.size()) {
                ll mnidx = 0;
                F(i, 1, ord.size()) if (cmp(ord[i][0], ord[mnidx][0])) mnidx = i;
                ans.push_back(ord[mnidx][0]);
                ord[mnidx].erase(ord[mnidx].begin());
                if (!ord[mnidx].size()) ord.erase(ord.begin() + mnidx); 
            }

            ans.insert(ans.begin(), i);
        };  
        ll time = 0;
        auto shit = dfs(dfs, 0);
        for (auto i: shit) {
            time += d[i]; ans += time * u[i];
        }
        return ans;
    }

    auto cmp = [&](int i,int j){
        return -u[i]*d[j] > -u[j]*d[i];
    };

    priority_queue<ll, vector<ll>, decltype(cmp)> pq(cmp);
    ans += d[0] * u[0];
    ll time = d[0];
    for (auto x: adj[0]) pq.push(x);
    while (pq.size()) {
        auto i = pq.top(); pq.pop();
        time += d[i];
        ans += time * u[i];
        for (auto y: adj[i]) pq.push(y); 
    }


    return ans;
}

Compilation message

job.cpp: In lambda function:
job.cpp:25:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 | #define F(i, l, r) for (ll i = l; i < (r); ++i)
      |                                     ^
job.cpp:66:17: note: in expansion of macro 'F'
   66 |                 F(i, 1, ord.size()) if (cmp(ord[i][0], ord[mnidx][0])) mnidx = i;
      |                 ^
job.cpp:73:9: warning: no return statement in function returning non-void [-Wreturn-type]
   73 |         };
      |         ^
job.cpp: In instantiation of 'scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(auto:23&&, ll)> [with auto:23 = scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)::<lambda(auto:23&&, ll)>&; vl = std::vector<long long int>; ll = long long int]':
job.cpp:75:31:   required from here
job.cpp:25:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 | #define F(i, l, r) for (ll i = l; i < (r); ++i)
      |                                     ^
job.cpp:66:17: note: in expansion of macro 'F'
   66 |                 F(i, 1, ord.size()) if (cmp(ord[i][0], ord[mnidx][0])) mnidx = i;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 15 ms 7772 KB Output is correct
6 Correct 27 ms 10532 KB Output is correct
7 Correct 40 ms 13136 KB Output is correct
8 Correct 53 ms 15952 KB Output is correct
9 Correct 54 ms 16112 KB Output is correct
10 Correct 69 ms 15928 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 51 ms 15924 KB Output is correct
13 Correct 52 ms 15944 KB Output is correct
14 Correct 53 ms 15956 KB Output is correct
15 Correct 55 ms 15952 KB Output is correct
16 Correct 52 ms 15924 KB Output is correct
17 Correct 52 ms 15956 KB Output is correct
18 Correct 53 ms 15956 KB Output is correct
19 Correct 53 ms 15900 KB Output is correct
20 Correct 52 ms 15960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 10072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 10072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 10340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 15 ms 7772 KB Output is correct
6 Correct 27 ms 10532 KB Output is correct
7 Correct 40 ms 13136 KB Output is correct
8 Correct 53 ms 15952 KB Output is correct
9 Correct 54 ms 16112 KB Output is correct
10 Correct 69 ms 15928 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 51 ms 15924 KB Output is correct
13 Correct 52 ms 15944 KB Output is correct
14 Correct 53 ms 15956 KB Output is correct
15 Correct 55 ms 15952 KB Output is correct
16 Correct 52 ms 15924 KB Output is correct
17 Correct 52 ms 15956 KB Output is correct
18 Correct 53 ms 15956 KB Output is correct
19 Correct 53 ms 15900 KB Output is correct
20 Correct 52 ms 15960 KB Output is correct
21 Runtime error 6 ms 10072 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -