Submission #978086

#TimeUsernameProblemLanguageResultExecution timeMemory
978086AybakSequence (APIO23_sequence)C++17
Compilation error
0 ms0 KiB
#include <iostream> int Count(int* arr, int len, int var) { int out = 0; for (uint64_t i = 0; i < len; ++i) { if (arr[i] == var) { ++out; } } return out; } int getMedianCount(int* arr, int len, int* sortedArrH) { memcpy(sortedArrH, arr, len * sizeof(int)); std::qsort(sortedArrH, len, sizeof(int), [](const void* x, const void* y) { if (*(int*)x > *(int*)y) return 1; return 0; }); if (len % 2 == 1) { return Count(sortedArrH, len, sortedArrH[len / 2]); } else { int M1 = Count(sortedArrH, len, sortedArrH[len / 2]); int M2 = Count(sortedArrH, len, sortedArrH[len / 2 - 1]); return std::max(M1, M2); } } int sequence(int N, std::vector<int> A) { int* arr = A.data(); int* sortedArrH = new int[N]; int LM = 0; for (uint64_t i = 0; i < N; ++i) { for (uint64_t j = i + 1; j < N + 1; ++j) { // array is i include j exclude int LMH = getMedianCount(&arr[i], j - i, sortedArrH); if (LMH > LM) { LM = LMH; } } } delete[] sortedArrH; return LM; }

Compilation message (stderr)

sequence.cpp: In function 'int Count(int*, int, int)':
sequence.cpp:5:28: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    5 |     for (uint64_t i = 0; i < len; ++i) {
      |                          ~~^~~~~
sequence.cpp: In function 'int getMedianCount(int*, int, int*)':
sequence.cpp:11:5: error: 'memcpy' was not declared in this scope
   11 |     memcpy(sortedArrH, arr, len * sizeof(int));
      |     ^~~~~~
sequence.cpp:2:1: note: 'memcpy' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | 
sequence.cpp: At global scope:
sequence.cpp:23:21: error: 'std::vector' has not been declared
   23 | int sequence(int N, std::vector<int> A) {
      |                     ^~~
sequence.cpp:23:32: error: expected ',' or '...' before '<' token
   23 | int sequence(int N, std::vector<int> A) {
      |                                ^
sequence.cpp: In function 'int sequence(int, int)':
sequence.cpp:24:16: error: 'A' was not declared in this scope
   24 |     int* arr = A.data();
      |                ^
sequence.cpp:27:28: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     for (uint64_t i = 0; i < N; ++i) {
      |                          ~~^~~
sequence.cpp:28:36: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         for (uint64_t j = i + 1; j < N + 1; ++j) { // array is i include j exclude
      |                                  ~~^~~~~~~