Submission #456303

# Submission time Handle Problem Language Result Execution time Memory
456303 2021-08-06T11:27:17 Z armand Distributing Candies (IOI21_candies) C++17
0 / 100
5000 ms 11944 KB
#include "candies.h"

#include <vector>
#include <algorithm>

bool all_pos(std::vector<int>& v)
{
	int n = v.size();
	for (int i = 0; i < n; i++)
		if (v[i] < 0)
			return false;
	return true;
}

std::vector<int> solve2(std::vector<int> c, std::vector<int> l,
	std::vector<int> r, std::vector<int> v)
{
	int i;
	int n = c.size();
	std::vector<int> s(n), p(n+1);
	int m = v.size();
	for (i = 0; i < n + 1; i++) p[i] = 0;
	for (i = 0; i < m; i++) {
		p[l[i]] += v[i];
		p[r[i] + 1] -= v[i];
	}
	for (i = 1; i < n + 1; i++)
		p[i] += p[i - 1];
	for (i = 0; i < n; i++)
		s[i] = std::min(p[i], c[i]);
	return s;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
	int i, j;
    int n = c.size();
    std::vector<int> s(n);
	int m = v.size();
	if (all_pos(v)) {
		s = solve2(c, l, r, v);
		return s;
	}
	for (i = 0; i < m; i++) {
		if (v[i] > 0)
			for (j = l[i]; j <= r[i]; j++)
				s[j] = std::min(c[j], s[j] + v[i]);
		else
			for (j = l[i]; j <= r[i]; j++)
				s[j] = s[j] + v[i] < 0 ? 0 : s[j] + v[i];
	}
    return s;
}
# 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 131 ms 11944 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 Correct 211 ms 5004 KB Output is correct
3 Correct 265 ms 3812 KB Output is correct
4 Execution timed out 5098 ms 7248 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 525 ms 5004 KB Output is correct
4 Correct 503 ms 2788 KB Output is correct
5 Execution timed out 5087 ms 7288 KB Time limit exceeded
6 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 -