답안 #318910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318910 2020-11-03T12:19:08 Z alextodoran Job Scheduling (IOI19_job) C++17
0 / 100
210 ms 262148 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "job.h"

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int n;

struct Cost
{
    int d, u;
};

Cost cost[N_MAX];

int parent[N_MAX];

vector <int> sons[N_MAX];

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

struct Node
{
    int u;
    Cost c;
};

bool operator < (const Node &u, const Node &v)
{
    return make_pair(u.c, u) > make_pair(v.c, u);
}

set <Node> notJoined[N_MAX];

void mergeSets (set <Node>* in, set <Node>* from)
{
    bool swapped = false;
    if(in->size() < from->size())
    {
        swap(in, from);
        swapped = true;
    }
    while(from->empty() == false)
    {
        in->insert(*from->begin());
        from->erase(from->begin());
    }
    if(swapped == true)
        swap(in, from);
}

bool isRoot[N_MAX];

void dfs (int u)
{
    for(int v : sons[u])
    {
        dfs(v);
        notJoined[u].insert(Node{v, cost[v]});
    }
    isRoot[u] = true;
    while(notJoined[u].empty() == false)
    {
        int v = notJoined[u].begin()->u;
        if(cost[u] < cost[v])
            break;
        notJoined[u].erase(notJoined[u].begin());
        isRoot[v] = false;
        cost[u].d += cost[v].d;
        cost[u].u += cost[v].u;
        mergeSets(&notJoined[u], &notJoined[v]);
    }
}

int order[N_MAX];

int curr;

void solveOne (int u)
{
    order[++curr] = u;
    vector <pair <Cost, int> > aux;
    for(int v : sons[u])
        //if(isRoot[v] == false)
            aux.push_back(make_pair(cost[v], v));
    sort(aux.begin(), aux.end());
    for(pair <Cost, int> p : aux)
        solveOne(p.second);
}

void solveAll (int u)
{
    solveOne(u);
    vector <int> aux;
    while(notJoined[u].empty() == false)
    {
        int v = notJoined[u].begin()->u;
        notJoined[u].erase(notJoined[u].begin());
        aux.push_back(v);
    }
    reverse(aux.begin(), aux.end());
    for(int v : aux)
        solveOne(v);
}

ll scheduling_cost (vector <int> p, vector <int> u, vector <int> d)
{
    n = p.size();
    for(int i = 1; i <= n; i++)
    {
        parent[i] = p[i - 1] + 1;
        cost[i] = Cost{d[i - 1], u[i - 1]};
    }
    for(int i = 2; i <= n; i++)
        sons[parent[i]].push_back(i);
    dfs(1);
    solveAll(1);
    int currTime = 0;
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int j = order[i];
        currTime += d[j - 1];
        ans += 1LL * currTime * u[j - 1];
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14444 KB Output is correct
2 Correct 10 ms 14452 KB Output is correct
3 Correct 11 ms 14604 KB Output is correct
4 Correct 13 ms 14700 KB Output is correct
5 Correct 55 ms 27160 KB Output is correct
6 Correct 89 ms 39464 KB Output is correct
7 Runtime error 208 ms 96176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14444 KB Output is correct
2 Correct 12 ms 14444 KB Output is correct
3 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14368 KB Output is correct
2 Correct 11 ms 14532 KB Output is correct
3 Correct 12 ms 14444 KB Output is correct
4 Correct 14 ms 14572 KB Output is correct
5 Runtime error 210 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14444 KB Output is correct
2 Incorrect 12 ms 14444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14444 KB Output is correct
2 Correct 10 ms 14452 KB Output is correct
3 Correct 11 ms 14604 KB Output is correct
4 Correct 13 ms 14700 KB Output is correct
5 Correct 55 ms 27160 KB Output is correct
6 Correct 89 ms 39464 KB Output is correct
7 Runtime error 208 ms 96176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -