Submission #318980

# Submission time Handle Problem Language Result Execution time Memory
318980 2020-11-03T15:51:45 Z alextodoran Job Scheduling (IOI19_job) C++17
0 / 100
12 ms 14444 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.u) > make_pair(v.c, v.u);
}

ll answer = 0;
set <Node> notJoined[N_MAX];

void mergeSets (int u, int v)
{
   answer += 1LL * cost[u].d * cost[v].u;
   cost[u].d += cost[v].d;
   cost[u].u += cost[v].u;
   set <Node> &in = notJoined[u];
   set <Node> &from = notJoined[v];

   if(in.size() < from.size())
       swap(in, from);
   while(from.empty() == false)
   {
       in.insert(*from.begin());
       from.erase(from.begin());
   }
}

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

int order[N_MAX];

int curr;

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]};
       answer += (ll)cost[i].u * cost[i].d;
   }
   for(int i = 2; i <= n; i++)
       sons[parent[i]].push_back(i);
   dfs(1);
   return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14444 KB Output is correct
2 Incorrect 10 ms 14444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14444 KB Output is correct
2 Incorrect 10 ms 14444 KB Output isn't correct
3 Halted 0 ms 0 KB -