10324 - Zeros and Ones
Moderator: Board moderators
10324 - Zeros and Ones
Why does this code get RE?
[c]
#include<stdio.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x;
long start,end,t,y,data[1000][2],cnt;
char *buffer,temp;
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;scanf("%s",buffer)!=EOF;cnt++)
{
scanf("%d",&n);
for(x=0;x<n;x++)
scanf("%ld %ld",&data[x][0],&data[x][1]);
printf("Case %d:\n",cnt);
for(x=0;x<n;x++)
{
start=data[x][0],end=data[x][1];
if(start>end)
SWAP(start,end,t);
for(temp=buffer[start],y=start;y<=end;y++)
if(buffer[y]!=temp)
break;
if(y<=end)
printf("No\n");
else
printf("Yes\n");
}
}
free(buffer);
}
[/c]
[c]
#include<stdio.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x;
long start,end,t,y,data[1000][2],cnt;
char *buffer,temp;
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;scanf("%s",buffer)!=EOF;cnt++)
{
scanf("%d",&n);
for(x=0;x<n;x++)
scanf("%ld %ld",&data[x][0],&data[x][1]);
printf("Case %d:\n",cnt);
for(x=0;x<n;x++)
{
start=data[x][0],end=data[x][1];
if(start>end)
SWAP(start,end,t);
for(temp=buffer[start],y=start;y<=end;y++)
if(buffer[y]!=temp)
break;
if(y<=end)
printf("No\n");
else
printf("Yes\n");
}
}
free(buffer);
}
[/c]
I rewrite the code as below
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x,*table;
long start,end,t,cnt,y;
char *buffer,temp,c;
table=(int *)malloc(sizeof(int)*1000000);
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;;cnt++)
{
for(x=0;(c=getchar())!='\n';x++)
if(c==EOF)
exit(0);
else
buffer[x]=c;
buffer[x]='\0';
if(!strlen(buffer))
exit(0);
printf("Case %d:\n",cnt);
for(y=0;y<strlen(buffer);y++)
{
table[y]=0;
if(y==0)
table[0]=buffer[0]-'0';
else
table[y]=buffer[y]-'0'+table[y-1];
}
scanf("%d",&n);
for(y=0;y<n;y++)
{
scanf("%ld %ld\n",&start,&end);
if(start>end)
SWAP(start,end,t);
if(start==0)
{
if(table[end]==0 || table[end]==end+1)
printf("Yes\n");
else
printf("No\n");
}
else
{
if(table[end]-table[start-1]==0 || table[end]-table[start-1]==end-start+1)
printf("Yes\n");
else
printf("No\n");
}
}
}
free(buffer);
}
[/c]
But I tested the code with '10324 < a.in'
a.in:
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x,*table;
long start,end,t,cnt,y;
char *buffer,temp,c;
table=(int *)malloc(sizeof(int)*1000000);
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;;cnt++)
{
for(x=0;(c=getchar())!='\n';x++)
if(c==EOF)
exit(0);
else
buffer[x]=c;
buffer[x]='\0';
if(!strlen(buffer))
exit(0);
printf("Case %d:\n",cnt);
for(y=0;y<strlen(buffer);y++)
{
table[y]=0;
if(y==0)
table[0]=buffer[0]-'0';
else
table[y]=buffer[y]-'0'+table[y-1];
}
scanf("%d",&n);
for(y=0;y<n;y++)
{
scanf("%ld %ld\n",&start,&end);
if(start>end)
SWAP(start,end,t);
if(start==0)
{
if(table[end]==0 || table[end]==end+1)
printf("Yes\n");
else
printf("No\n");
}
else
{
if(table[end]-table[start-1]==0 || table[end]-table[start-1]==end-start+1)
printf("Yes\n");
else
printf("No\n");
}
}
}
free(buffer);
}
[/c]
But I tested the code with '10324 < a.in'
a.in:
And the code replies0000011111
3
0 5
4 2
5 9
01010101010101010101010101111111111111111111111111111111111110000000000000000
5
4 4
25 60
1 3
62 76
24 62
1
1
0 0
But between case 2 and case 3 there's a newline.So the case 3 shouldn't be print out. How do I solve the problem?Case 1:
No
Yes
Yes
Case 2:
Yes
Yes
No
Yes
No
Case 3:
Yes
10324
Hey guys, whats up.
This is my first program with this online judge thing so I have to get used to it. I'm getting this compiler error message:
/* @JUDGE_ID: 20782HK 10324 C++ */
#include <stdio.h>
void process(char string[1000000], int pos1, int pos2)
{ bool answer = true;
if(pos1 > pos2)
{ int temp = pos2;
pos2 = pos1;
pos1 = temp;
}
for(int i = pos1; i <= pos2-1; i++)
{ if(string != string[i+1])
answer = false;
}
if(answer)
printf("Yes\n");
else if(!answer)
printf("No\n");
}
int main()
{ char string[1000000];
int count = 1,num;
while(scanf("%s", &string)==1)
{ printf("Case %d:\n",count);
scanf("%d",&num);
int x, y;
for(int i = 0; i < num; i++)
{ scanf("%d",&x);
scanf("%d",&y);
process(string,x,y);
}
count++;
}
return 0;
}
//@END_OF_SOURCE_CODE[/cpp]
Any suggestions would be appreciated
Thanx
This is my first program with this online judge thing so I have to get used to it. I'm getting this compiler error message:
... And here is my code : [cpp]//@BEGIN_OF_SOURCE_CODE/usr/lib/crt1.o: In function `_start':
/usr/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
/* @JUDGE_ID: 20782HK 10324 C++ */
#include <stdio.h>
void process(char string[1000000], int pos1, int pos2)
{ bool answer = true;
if(pos1 > pos2)
{ int temp = pos2;
pos2 = pos1;
pos1 = temp;
}
for(int i = pos1; i <= pos2-1; i++)
{ if(string != string[i+1])
answer = false;
}
if(answer)
printf("Yes\n");
else if(!answer)
printf("No\n");
}
int main()
{ char string[1000000];
int count = 1,num;
while(scanf("%s", &string)==1)
{ printf("Case %d:\n",count);
scanf("%d",&num);
int x, y;
for(int i = 0; i < num; i++)
{ scanf("%d",&x);
scanf("%d",&y);
process(string,x,y);
}
count++;
}
return 0;
}
//@END_OF_SOURCE_CODE[/cpp]
Any suggestions would be appreciated

Thanx
I don't know what is wrong. I copied and pasted from this thread and submitted it but i still get the #include compiler error. Here is my code. It is the exact same as above except without the // .
[cpp]/* @JUDGE_ID: 20782HK 10324 C++ */
#include <stdio.h>
void process(char string[1000000], int pos1, int pos2)
{ bool answer = true;
if(pos1 > pos2)
{ int temp = pos2;
pos2 = pos1;
pos1 = temp;
}
for(int i = pos1; i <= pos2-1; i++)
{ if(string != string[i+1])
answer = false;
}
if(answer)
printf("Yes\n");
else
printf("No\n");
}
int main()
{ char string[1000000];
int count = 1,num;
while(scanf("%s", &string)==1)
{ printf("Case %d:\n",count);
scanf("%d",&num);
int x, y;
for(int i = 0; i < num; i++)
{ scanf("%d",&x);
scanf("%d",&y);
process(string,x,y);
}
count++;
}
return 0;
}
[/cpp]
Don't know why it keeps giving me a compiler message. I hope my code is correct in case i ever fix the compiler errors so I can quit working on this stupid problem. Is there a compiler i could download that is similar to the judge's?? Anyway thanks a lot.
[cpp]/* @JUDGE_ID: 20782HK 10324 C++ */
#include <stdio.h>
void process(char string[1000000], int pos1, int pos2)
{ bool answer = true;
if(pos1 > pos2)
{ int temp = pos2;
pos2 = pos1;
pos1 = temp;
}
for(int i = pos1; i <= pos2-1; i++)
{ if(string != string[i+1])
answer = false;
}
if(answer)
printf("Yes\n");
else
printf("No\n");
}
int main()
{ char string[1000000];
int count = 1,num;
while(scanf("%s", &string)==1)
{ printf("Case %d:\n",count);
scanf("%d",&num);
int x, y;
for(int i = 0; i < num; i++)
{ scanf("%d",&x);
scanf("%d",&y);
process(string,x,y);
}
count++;
}
return 0;
}
[/cpp]
Don't know why it keeps giving me a compiler message. I hope my code is correct in case i ever fix the compiler errors so I can quit working on this stupid problem. Is there a compiler i could download that is similar to the judge's?? Anyway thanks a lot.
10324 -- Time Limit Exceed
Why does this code get TLE? I think my algorithm is fast enough. It should be the data reading problem.
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x,*table;
long start,end,t,cnt,y;
char *buffer,temp,c;
table=(int *)malloc(sizeof(int)*1000000);
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;;cnt++)
{
for(y=0;(c=getchar())!='\n';y++)
if(c==EOF)
exit(0);
else
buffer[y]=c;
buffer[y]='\0';
if(!strlen(buffer))
exit(0);
printf("Case %d:\n",cnt);
for(y=0;y<strlen(buffer);y++)
{
table[y]=0;
if(y==0)
table[0]=buffer[0]-'0';
else
table[y]=buffer[y]-'0'+table[y-1];
}
scanf("%d",&n);
for(y=0;y<n;y++)
{
scanf("%ld %ld",&start,&end);
if(start>end)
SWAP(start,end,t);
if(start==0)
{
if(table[end]==0 || table[end]==end+1)
printf("Yes\n");
else
printf("No\n");
}
else
{
if(table[end]-table[start-1]==0 || table[end]-table[start-1]==end-start+1)
printf("Yes\n");
else
printf("No\n");
}
}
c=getchar();
}
free(buffer);
}
[/c]
[c]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SWAP(x,y,t) (t=x,x=y,y=t)
void main(void)
{
int n,x,*table;
long start,end,t,cnt,y;
char *buffer,temp,c;
table=(int *)malloc(sizeof(int)*1000000);
buffer=(char *)malloc(sizeof(char)*1000000);
for(cnt=1;;cnt++)
{
for(y=0;(c=getchar())!='\n';y++)
if(c==EOF)
exit(0);
else
buffer[y]=c;
buffer[y]='\0';
if(!strlen(buffer))
exit(0);
printf("Case %d:\n",cnt);
for(y=0;y<strlen(buffer);y++)
{
table[y]=0;
if(y==0)
table[0]=buffer[0]-'0';
else
table[y]=buffer[y]-'0'+table[y-1];
}
scanf("%d",&n);
for(y=0;y<n;y++)
{
scanf("%ld %ld",&start,&end);
if(start>end)
SWAP(start,end,t);
if(start==0)
{
if(table[end]==0 || table[end]==end+1)
printf("Yes\n");
else
printf("No\n");
}
else
{
if(table[end]-table[start-1]==0 || table[end]-table[start-1]==end-start+1)
printf("Yes\n");
else
printf("No\n");
}
}
c=getchar();
}
free(buffer);
}
[/c]
This is making me mad. I am using AOL, which is bad I know, but I sent it to a yahoo account i made and it did not add anything to the e-mail. Now I tried it with yahoo, and it sends and doesn't return an #include message but yahoo mail adds a little advertisement at the bottom of every e-mail which sucks. So...it is probably my Internet provider. Got any suggestions about this problem. Man you are being a great help to me, thanks