답안 #706853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706853 2023-03-07T22:39:41 Z jeroenodb Job Scheduling (IOI19_job) C++14
5 / 100
59 ms 14268 KB
#include "job.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
bool comp(const array<ll,2>& a, const array<ll,2>& b) {
	return a[1]*b[0] < b[1]*a[0];
}
// abcde
struct DS {
	vector<array<ll,2>> ts;
	void root(int u,int d) { // O(1)
		ts.push_back({ts.empty()?u:ts.back()[0]+u,d});
	}

	void merge(DS& o) {
		vector<array<ll,2>> together;
		auto it = ts.rbegin(), it2 = o.ts.rbegin();
		ll u = ts.back()[0];
		ll ou = o.ts.back()[0];
		while(it!=ts.rend() or it2!=o.ts.rend()) {
			if(it2==o.ts.rend() or (it!=ts.rend() and comp(*it,*it2))) {
				(*it)[0]+=ou;
				together.push_back(*it);
				++it;
				
				if(it==ts.rend()) u=0;
				else u = (*it)[0];
			} else {
				(*it2)[0]+=u;
				together.push_back(*it2);
				++it2;
				if(it2==o.ts.rend()) ou=0;
				else ou = (*it2)[0];
			}
		}

		swap(ts,together);
		reverse(all(ts));
	}
	ll ans() {
		ll res=0;
		ll pd=0;
		for(auto& [u,d] : ts) {
			res+=u*d;
		}
		return res;
	}
};
long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
	// merge chains?
	int n = p.size();
	// just loop backwards, and maintain those?
	vector<DS> dp(n);
	for(int i=n-1;i>=0;--i) {
		// add root
		dp[i].root(u[i],d[i]);
		if(p[i]!=-1) {
			if(dp[p[i]].ts.empty()) swap(dp[i],dp[p[i]]);
			else dp[p[i]].merge(dp[i]);
		}
	}

	return dp[0].ans() ;
}

Compilation message

job.cpp: In member function 'll DS::ans()':
job.cpp:51:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |   for(auto& [u,d] : ts) {
      |             ^
job.cpp:50:6: warning: unused variable 'pd' [-Wunused-variable]
   50 |   ll pd=0;
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 14 ms 4016 KB Output is correct
6 Correct 27 ms 7464 KB Output is correct
7 Correct 41 ms 11868 KB Output is correct
8 Correct 51 ms 14256 KB Output is correct
9 Correct 51 ms 14208 KB Output is correct
10 Correct 53 ms 14220 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 52 ms 14200 KB Output is correct
13 Correct 54 ms 14228 KB Output is correct
14 Correct 50 ms 14216 KB Output is correct
15 Correct 53 ms 14232 KB Output is correct
16 Correct 51 ms 14192 KB Output is correct
17 Correct 51 ms 14260 KB Output is correct
18 Correct 52 ms 14208 KB Output is correct
19 Correct 59 ms 14220 KB Output is correct
20 Correct 53 ms 14268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 14 ms 4016 KB Output is correct
6 Correct 27 ms 7464 KB Output is correct
7 Correct 41 ms 11868 KB Output is correct
8 Correct 51 ms 14256 KB Output is correct
9 Correct 51 ms 14208 KB Output is correct
10 Correct 53 ms 14220 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 52 ms 14200 KB Output is correct
13 Correct 54 ms 14228 KB Output is correct
14 Correct 50 ms 14216 KB Output is correct
15 Correct 53 ms 14232 KB Output is correct
16 Correct 51 ms 14192 KB Output is correct
17 Correct 51 ms 14260 KB Output is correct
18 Correct 52 ms 14208 KB Output is correct
19 Correct 59 ms 14220 KB Output is correct
20 Correct 53 ms 14268 KB Output is correct
21 Correct 0 ms 304 KB Output is correct
22 Incorrect 0 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -