Submission #456298

# Submission time Handle Problem Language Result Execution time Memory
456298 2021-08-06T11:20:10 Z armand Distributing Candies (IOI21_candies) C++17
0 / 100
5000 ms 13348 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, j;
	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))
		return solve2(c, l, r, v);
	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;
}

Compilation message

candies.cpp: In function 'std::vector<int> solve2(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:18:9: warning: unused variable 'j' [-Wunused-variable]
   18 |  int i, j;
      |         ^
# 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 133 ms 13348 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 210 ms 6216 KB Output is correct
3 Correct 211 ms 5088 KB Output is correct
4 Execution timed out 5048 ms 8616 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 518 ms 6152 KB Output is correct
4 Correct 510 ms 3940 KB Output is correct
5 Execution timed out 5040 ms 8464 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 -