TLE in June cook off 2013 Attic Problem-C++

Why does TLE show up??
Following code is in C++ 4.3.2

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string.h>

#define TMAX 1000007
#define PMAX 1000007

int main()
{
 long long T;
 long long i;
 long long length;
 long long memory;
 long long count=0;
 long long answer=0;
 scanf("%lld",&T);

 while(T--)
 {
  char P[PMAX]="";
  answer=0;
  scanf("%s",P);
  length=strlen(P);
  memory=0;
  for(i=0;i<length;)
  {
   count=0;

   if(P[i]=='.')
   {
    while(P[i++]=='.')
    count++;

    if(count>memory)
    {
     answer++;
     memory=count;
    }
   }
   else
   i++;

  }
  printf("%lld\n",answer);
 }

 return EXIT_SUCCESS;
}

first of all alway indent your code because its tough for us to debug a code like yours.
here your mistakes :-

  1. use long long is slower than int prefer if u don’t require long long whch is not that big mistake

  2. here the biggest mistake remove char P[PMAX]=""; prefer char P[PMAX]; because its the main reason u are getting tle since for every testcase its taking a lot of time to execute do that single statement i don’t know the exact reason u can see if u remove char P[PMAX]=""; and place it before loop u will get accepted.
    Here the indented accepted code :-

    #include
    #include
    #include
    #include<string.h>
    #define TMAX 1000007
    #define PMAX 1000007
    int main()
    {
    int T;
    int i;
    int length;
    int memory;
    int count=0;
    int answer=0;
    scanf("%d",&T);
    while(T–) {
    char P[PMAX];
    answer=0;
    scanf("%s",P);
    length=strlen§;
    memory=0;
    for(i=0;i<length;)
    {
    count=0;
    if(P[i]==’.’)
    {
    while(P[i++]==’.’) count++;
    if(count>memory)
    {
    answer++;
    memory=count;
    }
    }
    else
    i++;
    }
    printf("%d\n",answer);
    }
    return 0;
    }

Why does TLE show up??
#include<stdio.h>
#include<string.h>

int main()
{
long long int t;
char s[500001];
long long int i=0,length=0,jump=0,day=0;

scanf("%Ld",&t);
while(t--)
{
	scanf("%s",&s);
	while(s[i]!='\0')
	{
		if(s[i]=='.')
		length++;
		else
		{
			if(jump>=length)
			length=0;
			else
			{
				day++;
				jump=length;
				length=0;
			}
		}
		i++;
		
	}
	printf("%lld",day);
	printf("\n");
	memset(s,0,sizeof(s)*sizeof(char));
	i=0;length=0;jump=0;day=0;
}
return 0;

}

@skrcode i think u should accept my answer instead of awarding a point :slight_smile:

plz check ur code again memset and i=0;… th line should be on top i guess

//