ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1021. Sacrament of the Sum

Who can help,Why I am always crash!!!!!!!!!!!!!
Posted by kkk 15 May 2002 10:29
My programme as follows



#include<stdio.h>
#define N 32767
#define M 10000
main()
{
  char a[32770];
  int state,data;
  long n,k;
  state=0;
  for(k=0;k<=N;k++)
    a[k]=0;
    scanf("%ld",&n);
  for(k=0;k<n;k++)
    {
       scanf("%d",&data);
       if(data>=0&&a[data]!=1&&a[data]!=3)a[data]+=1;
       else if(data<0&&a[data]!=2&&a[data]!=3)a[-data-1]+=2;
     }
  scanf("%ld",&n);
  for(k=0;k<n;k++)
    {
       scanf("%d",&data);
       if(M-data>=0&&M-data<=N)
     {
       if(a[M-data]==1||a[M-data]==3)
        state=1;
      }
       else if(M-data<0&&M-data>=-N-1)
     {
       if(a[data-M-1]==2||a[data-M-1]==3)
        state=1;
     }
     }
 if(state)printf("YES");
 else printf("NO");
}
.....ZZZzzzz
Posted by ECUST Multistar 15 May 2002 17:04
each element of the lists lays in the range from -32768 to 32767.
I don't think your array A is large enough....
I still get crash
Posted by kkk 16 May 2002 11:02
My pro as follows
  #include<stdio.h>
#define N 32767
#define M 10000
main()
{
  char a[60000];
  int state,data;
  long n,k;
  state=0;
  for(k=0;k<=40000;k++)
    a[k]=0;
    scanf("%ld",&n);
  for(k=0;k<n;k++)
    {
       scanf("%d",&data);
       if(data>=0)
       {
     if(a[data]!=1&&a[data]!=3)
        a[data]+=1;
    }
       else {
      if(a[data]!=2&&a[data]!=3)
         a[-data-1]+=2;
        }
     }
  scanf("%ld",&n);
  for(k=0;k<n;k++)
    {
       scanf("%d",&data);
       if(M-data>=0&&M-data<=N)
     {
       if(a[M-data]==1||a[M-data]==3)
        state=1;
      }
       else if(M-data<0&&M-data>=-N-1)
     {
       if(a[data-M-1]==2||a[data-M-1]==3)
        state=1;
     }
     }
 if(state)printf("YES");
 else printf("NO");

}