Submission #258631

# Submission time Handle Problem Language Result Execution time Memory
258631 2020-08-06T09:34:51 Z ipaljak Job Scheduling (IOI19_job) C++14
0 / 100
281 ms 262148 KB
#include "job.h"

#include <algorithm>
#include <vector>
#include <stack>

typedef long long llint;

using namespace std;

const int MAXN = 2e5 + 10;

bool bio[MAXN];

int n;

vector<int> p, u, d, D, U;
vector<int> v[MAXN];

void dfs(int node, int dd, int uu) {
  D[node] = dd + d[node];
  U[node] = uu + u[node];
  for (int nxt : v[node])
    dfs(nxt, D[node], U[node]);
}

bool cmp(int i, int j) {
  return U[i] * D[j] > U[j] * D[i];
}

llint scheduling_cost(vector<int> _p, vector<int> _u, vector<int> _d) {
  p = _p; u = _u; d = _d;
  n = (int) p.size();
  for (int i = 1; i < n; ++i) v[p[i]].push_back(i);

  llint ret = u[0] * d[0];
  int t = d[0];

  D.resize(n);
  U.resize(n);
  dfs(0, -d[0], -u[0]);

  vector<int> a(n - 1);
  for (int i = 1; i < n; ++i) a[i] = i;
  sort(a.begin(), a.end(), cmp);

  stack<int> s;
  for (int x : a) {
    if (bio[x]) continue;
    int _x = x;
    while (!bio[x]) {
      s.push(x);
      x = p[x];
    }
    while (!s.empty()) {
      int i = s.top(); s.pop();
      t += d[i];
      ret += (llint) t * u[i];
      bio[i] = true;
    }
  }
  return ret;
}

Compilation message

job.cpp: In function 'llint scheduling_cost(std::vector<int>, std::vector<int>, std::vector<int>)':
job.cpp:50:9: warning: unused variable '_x' [-Wunused-variable]
     int _x = x;
         ^~
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 281 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 280 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -