0

I'm trying to solve a problem and I'm using C++ to do so.

The first bit of my code is:

typedef long long ll;
...
ll M; std::cin >> M;
int clen[M];
clen[0] = 0;
clen[1] = 1;

for (ll i = 2; i < M; i++)
{
...

The problem is to use M = 1000000 (1e6), but this does not work. In particular, the first value of M where the program does not work as expected is 517988. It works for 517987 and presumably for all smaller numbers. I can only assume that the problem is with making my array, since the program should print things for i = 2 and so on, but instead it just waits for a bit and then ends.

Andrea B.
  • 113
  • 5
  • `int clen[M]` is not allowed in Standard C++, instead use `std::vector clen(M);` – M.M Apr 26 '20 at 01:01
  • The reason why it doesn't work is that your array is exhausting the stack memory. It is not legal C++ anyway, so use `std::vector` as already mentioned. – PaulMcKenzie Apr 26 '20 at 01:02

0 Answers0