Submission #1053327

# Submission time Handle Problem Language Result Execution time Memory
1053327 2024-08-11T10:30:22 Z tolbi Distributing Candies (IOI21_candies) C++17
0 / 100
5000 ms 13744 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define tol(bi) ((1LL)<<((int)(bi)))
template<typename T> vector<int32_t> normalize(vector<T> v){
	vector<int32_t> ret(v.size());
	for (int i = 0; i < v.size(); ++i)
	{
		ret[i]=v[i];
	}
	return ret;
}
vector<int32_t> distribute_candies(vector<int32_t> c, vector<int32_t> l, vector<int32_t> r, vector<int32_t> v) {
	int n = c.size();
	pair<int,int> pn[n];
	for (int i = 0; i < n; i++){
		pn[i]={c[i],i};
	}
	sort(pn,pn+n);
	int ind = 0;
	int mav = 0;
	int miv = 0;
	vector<int> ans(n,-1);
	for (int i = l.size()-1; i >= 0; i--){
		int val = v[i];
		if (val<0){
			miv-=val;
		}
		else {
			mav+=val;
		}
		while (ind<n){
			if (mav+miv>=pn[ind].first){
				if (val<0) ans[pn[ind].second]=mav;
				else ans[pn[ind].second]=pn[ind].first-miv;
				ind++;
			}
			else break;
		}
	}
	while (ind<n){
		ans[pn[ind].second]=mav;
	}
	return normalize(ans);
}

Compilation message

candies.cpp: In instantiation of 'std::vector<int> normalize(std::vector<_Tp>) [with T = long long int]':
candies.cpp:45:22:   required from here
candies.cpp:8:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int i = 0; i < v.size(); ++i)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 5095 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 13744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 5095 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -