how can these solutions pass time limit and codechef do u really check how much plagarism is there in long challenge ..

https://www.codechef.com/viewsolution/17785493

https://www.codechef.com/viewsolution/17665036

https://www.codechef.com/viewsolution/17815955

https://www.codechef.com/viewsolution/17627180

just take array size 100000 and fill each value by a particular number like 259

and there are a lot others …

Whats your point all the solution that u have linked above seems right and the time limit is generally 1 sec you assume u can do 10^8 operation per sec so 10^6 is fine. And about the plagiarism issue all the solutions are checked for plagiarism after contest.

The complexity may seem O(n^2) but is actually around O(nlogn) since whatever input you try, the maximum number of total votes would be around nlogn. Try to come up with a test case that would give TLE on these codes and you’ll realize why it’s true.

The reason why you’re getting runtime error on ideone is because you’re printing 10^5 integers which is more than the allowed output size on ideone. Try it on an offline compiler or just comment out the final print statements and it would work.

1 Like

time complexity is actually O(N\log{MAX}), where MAX is maximum number in the array.
Refer to this explanation TIME COMPLEXITY EXPLANATION.

Upvote it if you find it helpful I need karma points to contribute to the community (I don’t have any now)

1 Like

n can be as large as 100000
in the loop

  for( i=0; i<(n); i++)
  {
  	    if(i+1 < n)
  	    {
  	    	c[i]+=1;
  	    	c[i+1]+=1;
  	    } 

  	    for( j=i+2; j<n; j++)
        ......

}
how u see that it will pass time limit

here is a possible case

take n = 10^5 fill each element by 259

@vijju123

if u remove the if statement

there are 2 simple for loops with with each one running and the difference bw i and j is just two everytime

why isn’t this loop is simple

for(ll i=0;i<n;++i){

    for(ll j=i+2;j<n;++j){

        cout<<"hello ";

    }

    cout<<endl;
}