Page 3 of 9

Posted: Tue Apr 01, 2003 8:36 pm
by turuthok
You are calling strlen() excessively ... looks like that's what's causing TLE.

-turuthok-

Posted: Wed Apr 02, 2003 6:10 am
by coolbila
thx
you are right :D
the cost of strlen() is expensive

Posted: Fri Apr 18, 2003 6:53 pm
by Hisoka
change your array to 100000. :wink:

Posted: Thu Jun 12, 2003 9:59 pm
by keya
WA. What's wrong with my code? :(

[cpp]#include<stdio.h>
#include<string.h>
#define N 1000

char str1[N], str2[N];
long long i,j,len1,len2,no;

void main(void)
{
while(scanf("%s%s",&str1[0],&str2[0])==2)
{
len1 = strlen(str1);
len2 = strlen(str2);
i = j = no = 0;
if(len2<len1)
no = 1;
else
{
while(i<len1)
{
while(j<len2)
{
if(str2[j]==str1)
break;
j++;
}
if(j>=len2&&i<len1)
{
no = 1;
break;
}
i++;
}
}
if(no)
printf("No\n");
else
printf("Yes\n");
}
}[/cpp]

Posted: Sat Jun 14, 2003 3:42 pm
by Hisoka
input:

Code: Select all

maaf matif
maaf mataf
output:

Code: Select all

No
Yes
good luck. :)

10340 RTE

Posted: Wed Nov 12, 2003 6:18 pm
by r.z.
why is my code resulting RTE (SISVG)?

[c]#include<stdio.h>
#include<string.h>

void main()
{
char a[10000];
char b[10000];
int i,j;
int len;

while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}

}[/c]

don't know why....

Posted: Wed Nov 12, 2003 9:22 pm
by Hisoka

Code: Select all

char [100000]

Posted: Thu Nov 13, 2003 3:43 am
by r.z.
thanks

I got acc :wink:

10340 why my code is slower

Posted: Sun Feb 01, 2004 6:04 pm
by Morning
the problem is Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

my code is

[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
long long lo,loop1,loop2,flag;
char a[100000],b[100000];
while(cin>>a>>b)
{
if(strlen(a)>strlen(b))
{
cout<<"No"<<endl;
continue;
}
lo=0;
for(loop1=0;loop1<strlen(a);loop1++)
{
flag=0;
for(loop2=lo;loop2<strlen(b);loop2++)
{
if(b[loop2]==a[loop1])
{
flag=1;
lo=loop2+1;
break;
}
}
if(flag==0)
{
cout<<"No"<<endl;
break;
}
}
if(flag==1) cout<<"Yes"<<endl;

}
return 0;
}
[/cpp]
which got TLE
and there's someone else's code which can be AC and only use 0.001 second:
[cpp]
#include<stdio.h>
#include<string.h>

void main()
{
char a[100000];
char b[100000];
int i,j;
int len;

while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}

}
[/cpp]

i know i used tow "for" loop but i still think my code will spend the same time,because our algorithm seems the same:(
anyone who can tell me why mine is slower?

Posted: Sun Feb 01, 2004 6:27 pm
by Morning
Oh.i got the answer.strlen() takes my code a lot of time:)

Posted: Thu Apr 22, 2004 6:11 pm
by dalbertom
COUT's and CIN's are slower than PRINTF's and SCANF's, too :lol:

10340 why RTE?

Posted: Mon May 17, 2004 9:41 pm
by RodrigoPereira
:cry: It runs ok, but the judge returns RTE (Illegal Memory Reference). Why???

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  char * s = (char *)malloc(sizeof(char));
  char * t = (char *)malloc(sizeof(char));

  int i, tam, pos;
  char c;

  while (scanf("%s %s", s, t) != EOF){
    tam = strlen(s);
    pos = 0;
    for (i=0; i<tam; i++){
      c = s[i];
      while ((t[pos])&&(t[pos] != c))
        pos++;
    }

    if (t[pos])
      printf("Yes\n");
    else
      printf("No\n");

  }
  return 0;
}

Posted: Tue May 25, 2004 9:01 pm
by Jewel of DIU
You Have to use at least char array size of 1000000.
Use long as variable instead of int

Because pointer doesn't support that size.
Then u will not got RTE.

Posted: Tue May 25, 2004 10:49 pm
by RodrigoPereira
Thanx a lot, JoD! No more RTE!!! :lol:

...but i got WA :cry:

...does somebody have an input/output test?????

Posted: Wed May 26, 2004 9:00 pm
by Jewel of DIU
Try this input:
abbbbc abccccccccccc
Output:
No

But Yours is Yes.
Fix this, Then u will may got AC.
For further help you can mail me with ur code at:
nazmul_acm@yahoo.com

Wish u best of luck.