Submission #29972

# Submission time Handle Problem Language Result Execution time Memory
29972 2017-07-21T11:33:10 Z Bruteforceman Holiday (IOI14_holiday) C++11
24 / 100
5000 ms 6268 KB
#include"holiday.h"
#include "bits/stdc++.h"
long long frontR[100010];
long long frontB[100010];
long long backR[100010];
long long backB[100010];
std :: vector <int> P, Q;

long long sortSum(std :: vector <int> &v, int x, int take) {
	if(take < 0) return 0;	
	std :: priority_queue <int, std :: vector <int>, std :: greater <int> > q; 
	long long ans = 0;
	for(int i = 0; i <= x; i++) {
		q.push(v[i]);
		ans += v[i];
		while(q.size() > take) {
			ans -= q.top();
			q.pop();
		}
	}
	return ans;
}
void solveFrontR(int l, int r, int b, int e) {
	if(l > r) return ;
	int m = (l + r) >> 1;
	int opt = b;
	long long best = -1;
	for(int i = b; i <= e; i++) {
		long long o = sortSum(P, i, m - (i + 1));
		if(o > best) {
			best = o;
			opt = i;
		}
	}
	solveFrontR(l, m - 1, b, opt);
	solveFrontR(m + 1, r, opt, e);
	frontR[m] = std :: max(frontR[m], best);
}
void solveFrontB(int l, int r, int b, int e) {
	if(l > r) return ;
	int m = (l + r) >> 1;
	int opt = b;
	long long best = -1;
	for(int i = b; i <= e; i++) {
		long long o = sortSum(P, i, m - 2 * (i + 1));
		if(o > best) {
			best = o;
			opt = i;
		}
	}
	solveFrontB(l, m - 1, b, opt);
	solveFrontB(m + 1, r, opt, e);
	frontB[m] = std :: max(frontB[m], best);
}

void backCal(int d) {
	backB[d] = backR[d] = 0;
	
	std :: priority_queue <int, std :: vector <int>, std :: greater <int> > q;
	int take = 0;
	long long ans = 0;
	
	for(size_t i = 0; i < Q.size(); i++) {
		++take;
		if(take > d) break;
		q.push(Q[i]);
		ans += Q[i];
		
		while(q.size() + take > d) {
			ans -= q.top();
			q.pop();
		}
		backR[d] = std :: max(backR[d], ans);
	}
	
	take = 0;
	ans = 0;
	while(!q.empty()) q.pop();
	for(size_t i = 0; i < Q.size(); i++) {
		take += 2;
		if(take > d) break;
		
		q.push(Q[i]);
		ans += Q[i];
		
		while(q.size() + take > d) {
			ans -= q.top();
			q.pop();
		}
		backB[d] = std :: max(backB[d], ans);
	}
}

long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
	for(int i = 0; i < start; i++) {
		P.push_back(attraction[i]);
	}
	for(int i = start + 1; i < n; i++) {
		Q.push_back(attraction[i]);
	}
	std :: reverse(P.begin(), P.end());
	
	for(size_t i = 0; i <= d; i++) {
		backCal(i);
	} 	
	if(!P.empty()) {
		solveFrontR(1, d, 0, P.size() - 1);
		solveFrontB(1, d, 0, P.size() - 1);
	}
	
	long long ans = 0;
	for(int i = 0; i < d; i++) {
		ans = std :: max(ans, frontB[i] + attraction[start] + backR[d - i - 1]);
		ans = std :: max(ans, frontR[d - i - 1] + attraction[start] + backB[i]);
	}
	for(int i = 0; i <= d; i++) {
		ans = std :: max(ans, frontB[i] + backR[d - i]);
		ans = std :: max(ans, frontR[d - i] + backB[i]);
	}
    return ans;
}

Compilation message

holiday.cpp: In function 'long long int sortSum(std::vector<int>&, int, int)':
holiday.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(q.size() > take) {
                  ^
holiday.cpp: In function 'void backCal(int)':
holiday.cpp:69:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(q.size() + take > d) {
                         ^
holiday.cpp:86:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(q.size() + take > d) {
                         ^
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:103:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(size_t i = 0; i <= d; i++) {
                      ^
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
     int i, n_s;
            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5412 KB Output is correct
2 Correct 0 ms 5416 KB Output is correct
3 Correct 0 ms 5412 KB Output is correct
4 Correct 0 ms 5416 KB Output is correct
5 Correct 0 ms 5412 KB Output is correct
6 Correct 0 ms 5416 KB Output is correct
7 Correct 0 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5000 ms 6268 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4733 ms 5420 KB Output is correct
2 Correct 1136 ms 5412 KB Output is correct
3 Correct 3403 ms 5416 KB Output is correct
4 Correct 1159 ms 5412 KB Output is correct
5 Correct 1709 ms 5412 KB Output is correct
6 Correct 59 ms 5420 KB Output is correct
7 Correct 29 ms 5416 KB Output is correct
8 Correct 66 ms 5420 KB Output is correct
9 Correct 49 ms 5412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 0 KB -1: Interrupted system call
2 Halted 0 ms 0 KB -