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 1057. Amount of Degrees

I'm mad
Posted by Mato_No1 4 Sep 2010 19:20
Why does my program always get WA#1?
I have tried all the tests in the forum, and all of them are correct.
I think there is a very strange mistake in my program.

#include <stdio.h>
#define re(i, n) for (int i=0; i<n; i++)
#define rre(i, n) for (int i=n-1; i>=0; i--)
const int MAXN = 32;
int b, k;
long long c[MAXN][MAXN], res = 0;
void prp(void)
{
     re(i, MAXN) re(j, MAXN) if (i < j) c[i][j] = 0; else if (!j) c[i][j] = 1; else c[i][j] = c[i - 1][j - 1] * i / j;
}
long long xxx(long long v)
{
     int a[MAXN], len = 0;
     long long r0 = 0;
     while (v) {a[len++] = v % b; v /= b;}
     int k0 = k;
     rre(i, len) {
        int x = a[i];
        if (x >= 2) {r0 += c[i + 1][k0]; break;}
        if (x) {r0 += c[i][k0]; k0--;}
     }
     return r0;
}
int main(void)
{
    long long s, t;
    scanf("%lld%lld%d%d", &s, &t, &k, &b);
    prp();
    res = xxx(t + 1) - xxx(s);
    printf("%lld\n", res);
    return 0;
}


Edited by author 04.09.2010 20:07
I got AC
Posted by Mato_No1 4 Sep 2010 20:17
I know where the mistake is.
If "k0" is less than 0, it must exit.

Now I got AC.
Re: I got AC
Posted by Mato_No1 4 Sep 2010 20:19
The test is:
1 30 2 2 --> 10
Re: I'm mad
Posted by boyfox 21 Oct 2010 15:17
Right! Right! you must book ticket to madhouse, ok?