Submission #1257648

#TimeUsernameProblemLanguageResultExecution timeMemory
1257648kargneqHack (APIO25_hack)C++20
Compilation error
0 ms0 KiB
#include <vector>

#include "hack.h"

int hack() {
  const long long M = 1000000;
  vector<long long> x(M);
  iota(x.begin(), x.end(), 1);
  long long C = collisions(x);  // one query

  for (long long q = 0; q <= M/2; ++q) {
    long long denom = q * (q + 1) / 2;        // C(q+1,2)
    if (denom == 0) continue;                 // q=0 impossible when n>=2 and M>=1
    long long numer = M * q - C;
    if (numer <= 0) continue;
    if (numer % denom) continue;              // must divide
    long long n = numer / denom;
    if (n >= 2 && M / n == q)                 // floor(M/n) == q
      return (int) n;
  }
  // If you’re paranoid, fall back to smaller M or different set, but this loop finds it.
  return 2; // unreachable for valid tests
}

Compilation message (stderr)

hack.cpp: In function 'int hack()':
hack.cpp:7:3: error: 'vector' was not declared in this scope
    7 |   vector<long long> x(M);
      |   ^~~~~~
hack.cpp:7:3: note: suggested alternatives:
In file included from /usr/include/c++/11/vector:67,
                 from hack.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from hack.cpp:1:
/usr/include/c++/11/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
hack.cpp:7:10: error: expected primary-expression before 'long'
    7 |   vector<long long> x(M);
      |          ^~~~
hack.cpp:8:8: error: 'x' was not declared in this scope
    8 |   iota(x.begin(), x.end(), 1);
      |        ^
hack.cpp:8:3: error: 'iota' was not declared in this scope
    8 |   iota(x.begin(), x.end(), 1);
      |   ^~~~