Submission #222707

# Submission time Handle Problem Language Result Execution time Memory
222707 2020-04-13T20:57:05 Z opukittpceno_hhr Candies (JOI18_candies) C++17
8 / 100
7 ms 640 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 2001;
const int INF = 1e18 + 129;

int n;
int a[N];
int s1[N];
int s2[N];

int summ(int l, int r) {
	int tans = 0;
	if (l % 2 == 1) {
		tans = s2[r] - s2[l - 1];
	} else {
		tans = s1[r] - s1[l - 1];
	}
	return tans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	{
		for (int i = 1; i <= n; i++) {
			int v = a[i];
			if (i & 1) v *= -1;
			s1[i] = s1[i - 1] + v;
		}
		for (int i = 1; i <= n; i++) {
			int v = -a[i];
			if (i & 1) v *= -1;
			s2[i] = s2[i - 1] + v;
		}
	}
	set<pair<int, int>> seg;
	set<pair<int, pair<int, int>>> sss;
	auto real_erase = [&](pair<int, int> x) {
		seg.erase(x);
		sss.erase({summ(x.first, x.second), x});
	};
	auto real_insert = [&](pair<int, int> x) {
		seg.insert(x);
		sss.insert({summ(x.first, x.second), x});
	};
	for (int i = 1; i <= n; i++) {
		real_insert({i, i});
	}
	auto ers = [&](int l, int r) {
		auto it = seg.lower_bound({l, r});
		auto prv = it;
		if (it != seg.begin()) prv--;
		auto nxt = it;
		if (it != seg.end()) nxt++;
		if (seg.size() == 1) {
			seg.erase({l, r});
			return;
		}
		if (it == seg.begin()) {
			pair<int, int> we = *it;
			pair<int, int> next = *(nxt);
			real_erase(we);
			real_erase(next);
			return;
		}
		if (it == --seg.end()) {
			pair<int, int> we = *it;
			pair<int, int> prev = *(prv);
			real_erase(we);
			real_erase(prev);
			return;
		}
		pair<int, int> we = *it;
		pair<int, int> next = *(nxt);
		pair<int, int> prev = *(prv);
		real_erase(we);
		real_erase(next);
		real_erase(prev);
		real_insert({prev.first, next.second});
	};
	int curr = 0;
	vector<int> ans;
	while (!seg.empty()) {
		int mx = -INF;
		int lm = -1;
		int rm = -1;
		auto uu = *sss.rbegin();
		mx = uu.first;
		tie(lm, rm) = uu.second;
		ers(lm, rm);
		curr += mx;
		ans.push_back(curr);
	}
	for (auto t : ans) {
		cout << t << ' ';
	}
	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 7 ms 640 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 7 ms 640 KB Output is correct
15 Correct 7 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 7 ms 640 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 7 ms 640 KB Output is correct
15 Correct 7 ms 640 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Halted 0 ms 0 KB -