I was stuck in one question . I was getting half test case as correct answer , rest TLE . And as i know printf/scanf is faster than cout/cin , so i added printf/scanf everywhere . Now I am not even getting half answer as correct , instead i got a SIGSEGV error . Can anyone help me out where it went wrong

Can you please share the question link and also your approach?

1 Like

Question Contest Page | CodeChef
Approach Solution: 45763059 | CodeChef

Pay attention to compiler warnings!

Compiling aadarshsinha-ENDCORR.cpp
+ g++ -std=c++14 aadarshsinha-ENDCORR.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
aadarshsinha-ENDCORR.cpp: In function ‘int main()’:
aadarshsinha-ENDCORR.cpp:13:24: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll {aka long long int}’ [-Wformat=]
           scanf("%d", x);
aadarshsinha-ENDCORR.cpp:13:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
           scanf("%d", x);

1 Like

You should use a heap instead of a vector to avoid TLE, faster IO cannot be of much help if the basic approach is much slower. To avoid SIGSEGV you can check compiler warnings given by ssjgz for correct use of scanf.


Thank You everyone for spending your time and helping me out , now i got it .

1 Like