ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

Where is the mistake(1036)... Help plz. Or give me some test...(+)
Послано Algorist 7 мар 2002 22:49
Here is my code. I tested it with 50 100 (the test posted in the
forum) and it worked OK.... but when I submitted it, I got WA... Why?


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX(a,b) a>b?a:b
#define     MAXL            300
#define     _MAX_N          51
#define     _MAX_S          501

struct large {
short num[MAXL]; // The number itself. 1234 is stored as 4321
int sz; // sz is the quantity of digits
};

large m1[_MAX_S],m2[_MAX_S];
large one,zero,t;

void add(large &n1,large n2) {
int size=MAX(n1.sz,n2.sz);
int ost=0;
int i;
     n1.sz=size;
     for (i=0;i<size;i++) {
         n1.num[i]=n1.num[i]+n2.num[i]+ost;
         if (n1.num[i]>9) {
            n1.num[i]-=10;
            ost=1;
         } else ost=0;
     }
     if (ost==1) {
        size++;
        n1.sz=size;
        n1.num[size-1]=1;
     }
}

void init() {
int i,j;
     for (i=0;i<_MAX_S;i++) {
         m2[i].sz=0;
         for (j=0;j<MAXL;j++)
             m2[i].num[j]=0;
     }

}

void calc(int n, int sum) {
int i,j,k;
    for (i=0;i<=sum;i++)
        if (i<10) m1[i]=one; else m1[i]=zero;
    for (i=2;i<=n;i++) {
        for (j=0;j<=sum;j++) {
            for (k=0;k<=9;k++)
             if (j>=k) add(m2[j],m1[j-k]); else break;
        }
        memcpy(m1,m2,sizeof(m2));
        init();
    }
}

void print(large x) {
int i;
     for (i=x.sz-1;i>=0;i--)
         printf("%d",x.num[i]);
     printf("\n");
}

void lsqr(large &x) {
short res[MAXL][MAXL];
int ost,ind1,ind2,i,j,sum;
     ost=0;
     memset(&res,0,sizeof(res));
     for (i=0;i<x.sz;i++) {
         ind1=i;
         for (j=0;j<x.sz;j++) {
             ind2=ind1+j;
             res[ind1][ind2]=x.num[i]*x.num[j]+ost;
             ost=res[ind1][ind2]/10;
             res[ind1][ind2]%=10;
         }
         if (ost>0) res[ind1][ind1+j]=ost;
         ost=0;
     }
     ost=0;
     for (i=0;i<MAXL;i++) {
         sum=0;
         for (j=0;j<MAXL;j++)
             sum+=res[j][i];
         x.num[i]=sum+ost;
         ost=x.num[i]/10;
         x.num[i]%=10;
     }
     x.num[i]=ost;
     for (x.sz=MAXL-1;x.sz>=0;x.sz--)
      if (x.num[x.sz]!=0) break;
     x.sz++;
}

int main() {
int n,s;
    one.sz=1;one.num[0]=1;
    zero.sz=1;zero.num[0]=0;
    scanf("%d %d",&n,&s);
    if ((s%2)==1) {
       printf("0\n");
       return 0;
    }
    s/=2;
    calc(n,s);
    t=m1[s];
    lsqr(t);
    print(t);
}
here (+)
Послано Sam Green 8 мар 2002 13:12
49 998: wrong "", correct "0"
49 1000: wrong "", correct "0"
50 998: wrong "", correct "0"
50 1000: wrong "", correct "0"

call to mind something ? :)
10x, i got AC
Послано Algorist 8 мар 2002 13:49
> 49 998: wrong "", correct "0"
> 49 1000: wrong "", correct "0"
> 50 998: wrong "", correct "0"
> 50 1000: wrong "", correct "0"
>
> call to mind something ? :)