답안 #245798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245798 2020-07-07T12:30:01 Z quocnguyen1012 Job Scheduling (IOI19_job) C++14
26 / 100
914 ms 20600 KB
#ifndef LOCAL
#include "job.h"
#endif // LOCAL
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e5 + 5;

ll cost[maxn], tim[maxn];
int N;
ll lab[maxn], mark[maxn];
ll t = 0, res;

ll finds(int u)
{
  if(lab[u] == u) return u;
  return lab[u] = finds(lab[u]);
}

struct cmp
{
  bool operator ()(ll a, ll b) const
  {
    return cost[a] * tim[b] > cost[b] * tim[a];
  }
};
set<ll, cmp> se;

ll scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d)
{
  N = p.size();
  for(int i = 0; i < N; ++i){
    tim[i] = d[i];
    cost[i] = u[i];
    lab[i] = i;
  }
  for(int i = 0; i < N; ++i)
    se.insert(i);
  for(int i = 0; i < N; ++i){
    ll now = *se.begin();
    se.erase(now);
    //cerr << now << '\n';
    if(p[now] == -1 || mark[finds(p[now])]){
      t += tim[now];
      res += 1ll * cost[now] * t;
      mark[now] = 1;
      continue;
    }
    ll top = finds(p[now]);
    se.erase(top);
    res -= 1ll * cost[top] * tim[now];
    cost[top] += cost[now];
    tim[top] += tim[now];
    se.insert(top);
    lab[now] = top;
  }
  return res;
}

#ifdef LOCAL
signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  int n; cin >> n;
  vector<int> p(n), u(n), d(n);
  for(auto & it : p) cin >> it;
  for(auto & it : u) cin >> it;
  for(auto & it : d) cin >> it;
  cout << scheduling_cost(p, u, d);
}
#endif // LOCAL
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 91 ms 5080 KB Output is correct
6 Correct 295 ms 9800 KB Output is correct
7 Correct 490 ms 14456 KB Output is correct
8 Correct 820 ms 19132 KB Output is correct
9 Correct 808 ms 19088 KB Output is correct
10 Correct 914 ms 19320 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 799 ms 19184 KB Output is correct
13 Correct 390 ms 19320 KB Output is correct
14 Correct 385 ms 20088 KB Output is correct
15 Correct 221 ms 19192 KB Output is correct
16 Correct 265 ms 20600 KB Output is correct
17 Correct 750 ms 19192 KB Output is correct
18 Correct 848 ms 19064 KB Output is correct
19 Correct 184 ms 19112 KB Output is correct
20 Correct 159 ms 20600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Incorrect 12 ms 1280 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 776 ms 19192 KB Output is correct
3 Correct 777 ms 19196 KB Output is correct
4 Incorrect 754 ms 19064 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 91 ms 5080 KB Output is correct
6 Correct 295 ms 9800 KB Output is correct
7 Correct 490 ms 14456 KB Output is correct
8 Correct 820 ms 19132 KB Output is correct
9 Correct 808 ms 19088 KB Output is correct
10 Correct 914 ms 19320 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 799 ms 19184 KB Output is correct
13 Correct 390 ms 19320 KB Output is correct
14 Correct 385 ms 20088 KB Output is correct
15 Correct 221 ms 19192 KB Output is correct
16 Correct 265 ms 20600 KB Output is correct
17 Correct 750 ms 19192 KB Output is correct
18 Correct 848 ms 19064 KB Output is correct
19 Correct 184 ms 19112 KB Output is correct
20 Correct 159 ms 20600 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Incorrect 5 ms 384 KB Output isn't correct
24 Halted 0 ms 0 KB -