Hi,
I can imagine two possibilities to achieve that:
int x[10] = { [0 ... 9] = 2 };
int a[10][10] = { [0 ... 9][0 ... 9] = 1 };
Note the spaces around the "..."!
The first line is an example for a one-dimensional array, the second for two dimensions.
This is a GNU extension for the C Compiler, so it won't work in most places, especially not within the C++ Compiler. But it should work on SPOJ. I wouldn't use such constructs myself, though.
A more common way to do it is:
int x[10];
void init()
{
memset(x, 0xFF, 10 * sizeof(int));
}
There are some variations, so you can specift sizeof(x) instead of 10 * sizeof(int) if you want to initialize the whole array and the size is known at compile time.
But the important thing to remember is: That value is assigned bytewise, not elementwise. Therefore memsetting the value 0x01 will result in integers with a value of 0x01010101 = 16843009, not 1 as one might expect.
But in essence: The initialization shouldn't be the bottleneck...
Greetings