Hi, I'm getting this RE message
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before crash, it ran during 0.170 seconds
This sucks. One thing I can say is that when I run on my comp using Microsoft Visual C++, and I try to type in a huge string of 0's and 1's i can only input 253 digits and then it stops taking in digits. It just stops and I don't know why. O yea and my code is kinda weird. Here is my code:
[cpp]#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void subprocess(int *buffer, int p, char dir, int & count, int pos1, int pos2,int length)
{
if(p < length)
{ if(int(buffer[p]) <= pos2 && int(buffer[p]) >= pos1)
count++;
else
dir = '\0';
if(dir == 'u')
{ p+=1;
subprocess(buffer,p,dir,count,pos1,pos2,length);
}
else if(dir == 'd')
{ p-=1;
subprocess(buffer,p,dir,count,pos1,pos2,length);
}
}
}
void process(int* buffer, int length, int pos1, int pos2, int & temp, int stringlength)
{ int start=0, n = int(length/2), end = length-1, count = 0;
if(pos1 > pos2)
{ temp = pos2;
pos2 = pos1;
pos1 = temp;
}
while(n < length)
{ if(start==end)
break;
if(int(buffer[n]) <= pos2 && int(buffer[n]) >= pos1)
{ int p = n;
char up = 'u',down = 'd';
subprocess(buffer,p,up,count,pos1,pos2,length);
subprocess(buffer,p,down,count,pos1,pos2,length);
count--;
break;
}
else if(int(buffer[n]) > pos2)
{ end = n;
if(int((start+n)/2) == n)
break;
n = int((start+n)/2);
}
else if(int(buffer[n]) < pos1)
{ start= n;
if(int((end+n)/2)==n)
break;
n = int((end+n)/2);
}
}
int difference = pos2-pos1+1;
if((count == 0 || count == difference)&& pos2 < stringlength)
printf("Yes\n");
else
printf("No\n");
}
int main()
{
for(int i=1;; i++)
{ int * buffer,d(0);
char c;
buffer=(int *)malloc(sizeof(int)*1000000);
if (buffer==NULL) exit (1);
int a;
for(a=0 ; (c=getchar())!='\n' ;a++)
{ if(c==EOF)
exit(0);
else
{ if(c=='0')
{ buffer[d] = a;
d++;
}
}
}
int stringlength = a,length = d,num,x, y,temp;
printf("Case %d:\n",i);
scanf("%d",&num);
for(int i = 0; i < num; i++)
{ scanf("%d",&x);
scanf("%d",&y);
if(x >= stringlength || y >= stringlength)
printf("No\n");
else
process(buffer,length,x,y,temp,stringlength);
}
free(buffer);
getchar();
}
return 0;
}[/cpp]
Now I'm just a high school student, so If my code is really bad please tell me because I would not know better. Basically what it does is that it takes in the positions of zeroes in an array. Then it searches the array for a position that contains a position of a zero within the input positions. Once it finds it uses a recursive function to search up and down from that spot in that array. It counts the times it finds valid positions of zeroes. If it the count is 0 or the difference between the two input positions then that means that they are all 1's or 0's, respectively.
I tried this program before and it gave me a TLE so I had to go back to the drawing board to make a less time consuming program.
Anyway if you have any suggestions on how to fix my RE problem please give them to me =). Thank you very much.