First I would like to say, that C++ is not my basic language, and I ask for forgiveness if it's basic knowledge.
My problem is that I have to overcome spoj time limit with my algorithm. I am confident that algorithm itself is good (and I dont't want help with it ;) ), but data passed to it is given from console.
I need to read random number of integers (limit is 10^7) in single line terminated by EOF symbol. So far I got something like that:
cin.tie(NULL);
std::ios::sync_with_stdio(false);
vector <unsigned int > vector_of_int;
...
std::string str;
std::getline(std::cin, str);
std::istringstream sstr(str);
unsigned int n;
while(sstr >> n){
vector_of_int.push_back(n);
}
However - this is not fast enough to fit in time limit for this task. So question is - is there any faster (spoj-friendly) way to read this kind of data?
My results are
number status signal time memory
test 0 passed OK 0.0s 2828KB
test 1 passed OK 0.0s 2828KB
test 2 passed OK 0.01s 2828KB
test 3 passed OK 0.0s 2828KB
test 4 passed OK 0.01s 2828KB
test 5 passed OK 0.0s 2828KB
test 6 passed OK 0.0s 2940KB
test 7 passed OK 0.04s 3060KB
test 8 passed OK 0.24s 3452KB
test 9 passed OK 0.44s 3452KB
test 10 passed OK 0.84s 3452KB
test 11 TLE OK 1.01s 27784KB
test 12 TLE OK 1.01s 28056KB
EDIT:
Results after commenting vector_of_int.push_back(n);
line
number status signal time memory
test 0 passed OK 0.0s 2828KB
test 1 wrong answer OK 0.0s 2828KB
test 2 wrong answer OK 0.0s 2828KB
test 3 wrong answer OK 0.0s 2828KB
test 4 wrong answer OK 0.0s 2828KB
test 5 wrong answer OK 0.0s 2828KB
test 6 wrong answer OK 0.01s 2964KB
test 7 runtime error SIGSEGV 0.02s 3128KB
test 8 runtime error SIGSEGV 0.06s 5504KB
test 9 runtime error SIGSEGV 0.09s 8032KB
test 10 runtime error SIGSEGV 0.16s 13224KB
test 11 runtime error SIGSEGV 0.21s 14976KB
test 12 runtime error SIGSEGV 0.28s 23440KB
EDIT 2:
I've noticed that input line is terminated by EOF instead of new line.