Submission #549447

# Submission time Handle Problem Language Result Execution time Memory
549447 2022-04-15T20:09:31 Z kilikuma Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
int* distribute_candies(int c[], int l[], int r[], int v[]) {
  int N = sizeof(c) / sizeof(c[0]);
  int Q = sizeof(l) / sizeof(l[0]);
  int S[N + 1] = {0};
  for (int i = 0; i < Q; i ++) {
    for (int j = l[i]; j <= r[i]; j ++) {
      if (v[i] < 0)
        S[j] = min(c[j], S[j] + v[i]);
      else
        S[j] = max(0, S[j] + v[i]);
    }
  }
  return S;
}

Compilation message

candies.cpp: In function 'int* distribute_candies(int*, int*, int*, int*)':
candies.cpp:4:18: warning: 'sizeof' on array function parameter 'c' will return size of 'int*' [-Wsizeof-array-argument]
    4 |   int N = sizeof(c) / sizeof(c[0]);
      |                 ~^~
candies.cpp:3:29: note: declared here
    3 | int* distribute_candies(int c[], int l[], int r[], int v[]) {
      |                         ~~~~^~~
candies.cpp:5:18: warning: 'sizeof' on array function parameter 'l' will return size of 'int*' [-Wsizeof-array-argument]
    5 |   int Q = sizeof(l) / sizeof(l[0]);
      |                 ~^~
candies.cpp:3:38: note: declared here
    3 | int* distribute_candies(int c[], int l[], int r[], int v[]) {
      |                                  ~~~~^~~
candies.cpp:15:10: warning: address of local variable 'S' returned [-Wreturn-local-addr]
   15 |   return S;
      |          ^
candies.cpp:6:7: note: declared here
    6 |   int S[N + 1] = {0};
      |       ^
/usr/bin/ld: /tmp/ccCUVWdU.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status