Submission #742846

# Submission time Handle Problem Language Result Execution time Memory
742846 2023-05-17T03:57:08 Z t6twotwo Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
	int n = c.size();
	int m = v.size();
	for (auto &x : r) {
		x++;
	}
	if (n <= 2000 && q <= 2000) {
		vector<int> a(n);
		for (int i = 0; i < m; i++) {
			for (int j = l[i]; j < r[i]; j++) {
				a[j] = min(c[j], max(a[j] + v[j], 0));
			}
		}
		return a;
	}
	if (*min_element(v.begin(), v.end()) > 0) {
		vector<ll> pfs(n + 1);
		for (int i = 0; i < m; i++) {
			pfs[l[i]] -= v[i];
			pfs[r[i]] += v[i];
		}
		for (int i = 0; i < n; i++) {
			pfs[i + 1] += pfs[i];
		}
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			a[i] = min(1LL * c[i], pfs[i]);
		}
		return a;
	}
	return {};
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:10:19: error: 'q' was not declared in this scope
   10 |  if (n <= 2000 && q <= 2000) {
      |                   ^
candies.cpp:20:10: error: 'll' was not declared in this scope; did you mean 'l'?
   20 |   vector<ll> pfs(n + 1);
      |          ^~
      |          l
candies.cpp:20:12: error: template argument 1 is invalid
   20 |   vector<ll> pfs(n + 1);
      |            ^
candies.cpp:20:12: error: template argument 2 is invalid
candies.cpp:22:7: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   22 |    pfs[l[i]] -= v[i];
      |       ^
candies.cpp:23:7: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   23 |    pfs[r[i]] += v[i];
      |       ^
candies.cpp:26:7: error: invalid types 'int[int]' for array subscript
   26 |    pfs[i + 1] += pfs[i];
      |       ^
candies.cpp:26:21: error: invalid types 'int[int]' for array subscript
   26 |    pfs[i + 1] += pfs[i];
      |                     ^
candies.cpp:30:30: error: invalid types 'int[int]' for array subscript
   30 |    a[i] = min(1LL * c[i], pfs[i]);
      |                              ^