Submission #447156

# Submission time Handle Problem Language Result Execution time Memory
447156 2021-07-24T18:52:55 Z LucaDantas Distributing Candies (IOI21_candies) C++17
0 / 100
149 ms 10820 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep = ""; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const set<A> &s) { os << '{'; string sep = ""; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &m) { os << '{'; string sep = ""; for (const auto &x : m) os << sep << x.first << " -> " << x.second, sep = ", "; return os << '}'; }
 
void debug() { cerr << endl; }
template<typename Ini, typename... Fim> void debug(Ini I, Fim... F) { cerr << I; if(sizeof...(F)) cerr << ", "; debug(F...);}
#define db(...) cerr << "DEBUG (" << #__VA_ARGS__ << ") == ", debug(__VA_ARGS__)
 
constexpr int inf = 0x3f3f3f3f;
 
// subtask l = 0, r = n-1 for all events
 
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = (int)(c.size());
	vector<int> ans(n);
	vector<pair<int,int>> td;
	for(int i = 0; i < n; i++)
		td.push_back({c[i], i});
	sort(td.begin(), td.end(), greater<pair<int,int>>());
	vector<int> seq;
	int add = 0, m = (int)(v.size());
	for(int i = 0; i < m; i++) {
		if((v[i] > 0) == (add > 0) || !add) add += v[i], add = max(-inf, min(add, inf));
		else seq.push_back(max(0, min(inf, add + (seq.size() ? seq.back() : 0)))), add = v[i];
	}
	if(add) seq.push_back(max(0, min(inf, add + (seq.size() ? seq.back() : 0))));
	
	vector<pair<int,int>> gld;
	int mn = inf;
	for(int i = (int)(seq.size())-1; i >= 0; i--) {
		mn = min(mn, seq[i]);
		gld.push_back({seq[i], seq[i] - mn}); // intervalo que fica ativo
	}
	sort(gld.begin(), gld.end());
	reverse(gld.begin(), gld.end());
	
	int acabado = 0;
	set<pair<int,int>> atv, maior;
 
	for(int i = 0, j = 0; i < n; i++) {
		for(; j < (int)(gld.size()) && gld[j].first >= td[i].first; j++)
			atv.insert({gld[j].second, gld[j].first}), maior.insert(gld[j]);
		while(atv.size() && atv.begin()->first >= td[i].first) {
			acabado = max(acabado, atv.begin()->second - atv.begin()->first);
			maior.erase({atv.begin()->second, atv.begin()->first});
			atv.erase(atv.begin());
		}
		ans[td[i].second] = seq.back() - acabado;
		if(maior.size()) ans[td[i].second] = min(ans[td[i].second], seq.back() - (maior.rbegin()->first - td[i].first));
	}
 
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 10820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -