MATCHS-TLE for all test cases except first test case

Please help me to identify that where is my code going wrong…
https://www.codechef.com/viewsolution/24249257

2 Likes

i have just some parts of your code ( only 2 lines) and got a AC
link : CodeChef: Practical coding for everyone
added these two lines:
1.for fast IO
ios_base::sync_with_stdio(false);
cin.tie(NULL);
2. you used q as long long int array of a large size i used vector instead of array so that i can save space.

1 Like

Why I am getting TLE if I can’t use vector in place of array?

its interesting , there is no problem with using an array the problem lies using the following statement
int q[100000]={ }; or int q[100000]={0};
replace the statement with int q[100000];
you will get an AC.
I think that the array is set to a given value so it consumes time and results in a TLE , though I am not sure about this.

2 Likes

Sorry, i was wrong. I tried to change your code. Moving the initialization of the variables and some conditions, and I got AC. CodeChef: Practical coding for everyone

Ok, I found the cause of the problem with some tests.
https://www.codechef.com/viewsolution/24268129
https://www.codechef.com/viewsolution/24268139
The real problem is the inizialization of long long int q[100000] = {}; only by moving this line of code out of the while loop, we get AC.
@yashshahiiitdm

1 Like

Thanks, @anon13835146, @baby_stark
I got it…