EDIT: Actual possible solution at the end.
First of all as Ted Lyngmo already said: Your array initialization is not C++ standard compliant (i think some compilers support it, but i have never used it). You could either use C++ STL vectors or pointers.
Using pointers your code could look like this (note that you have to delete every memory that you initialize):
int * arr = new int[K];
// Do your test case and before (!) the end of
// the while loop free the memory
delete[] arr;
Using vectors your code could look like this (std::vector
takes care of all memory management for you):
#include <vector>
std::vector<int> arr(K);
One thing that could cause a SIGSEGV is an invalid write to an address. If for example K is less than 2 you are writing to memory locations that you don't safely own and the OS could kill your process. Your algorithm either doesn't work for K < 2 or it is missing an edge case.
// Make sure that K >= 2
// If K < 2 the following lines could cause SIGSEGV
arr[0] = d0;
arr[1] = d1;
Also you might want to check how much memory you are actually allocating with your vector.
The task on CodeChef specifies: 2 ≤ K ≤ 10^12
You are trying to allocate every digit for your number as an integer. An integer usually takes about 4 bytes so on difficult cases your program attempts to allocate 4B * K = 3.64 TiB
of memory. That might be the problem as i don't think you have multiple terabytes of RAM at hand. You might want to try a different attempt at solving the puzzle that doesn't allocate as much memory.
Note: a single decimal digit takes a bit less than 4 bit (half a byte) to store. which is still more than you can allocate. So you might want to think about a solution where you dont have to calculate in beforehand every single digit, but iterate through the digits of your unknown number.