답안 #555658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555658 2022-05-01T10:13:04 Z fleimgruber 휴가 (IOI14_holiday) C++17
23 / 100
21 ms 5792 KB
// still only subtask 2
#include "holiday.h"
#include <bits/stdc++.h>

using namespace std;

struct SegmentTree {
	int n;
	struct Value {
		long long sum = 0;
		int size = 0;
		friend Value operator+(const Value& a, const Value& b) {
			return { a.sum + b.sum, a.size + b.size };
		}
	};
	vector<Value> tree;

	int round_up(int n) {
		while (n & (n-1))
			n++;
		return n;
	}

	SegmentTree(int n_) : n(round_up(n_)), tree(2*n) { }

	void set(int i, const Value& value) {
		i += n;
		tree[i] = value;
		for (i /= 2; i > 0; i /= 2)
			tree[i] = tree[2*i] + tree[2*i+1];
	}

	long long descend(int budget) {
		if (tree[1].size <= budget)
			return tree[1].sum;
		long long sum = 0;
		for (int i = 1; i < n;)
			if (tree[2*i].size > budget)
				i = 2*i;
			else {
				sum += tree[2*i].sum;
				budget -= tree[2*i].size;
				i = 2*i+1;
			}
		return sum;
	}
};

long long findMaxAttraction(int n, int start, int d, int attraction[]) {
	vector<int> sorted(n), rank(n);
	iota(sorted.begin(), sorted.end(), 0);
	sort(sorted.begin(), sorted.end(), [&](int i, int j) {
		return attraction[i] > attraction[j];
	});
	for (int i = 0; i < n; i++)
		rank[sorted[i]] = i;
	SegmentTree tree(n);
	long long ans = 0;
	for (int r = 0; r < min(n, d); r++) {
		tree.set(rank[r], { attraction[r], 1 });
		ans = max(ans, tree.descend(d - r));
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Incorrect 1 ms 692 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 5588 KB Output is correct
2 Correct 15 ms 5716 KB Output is correct
3 Correct 17 ms 5616 KB Output is correct
4 Correct 16 ms 5588 KB Output is correct
5 Correct 21 ms 5580 KB Output is correct
6 Correct 6 ms 2004 KB Output is correct
7 Correct 11 ms 3156 KB Output is correct
8 Correct 13 ms 3256 KB Output is correct
9 Correct 4 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Incorrect 1 ms 852 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 5752 KB Output is correct
2 Correct 20 ms 5792 KB Output is correct
3 Incorrect 12 ms 3292 KB Output isn't correct
4 Halted 0 ms 0 KB -