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 1032. Find a Multiple

Have problem, need help.
Posted by Stefan Ciobaca 25 Feb 2002 01:52
I solved this problem, but I get Wrong Answer.
The thing is that i couldn't possibly get Wrong Answer
if my solution to the problem was wrong. I would get
timeout. (notice the for(;;);).

Can anyone tell me what is wrong?



#include <stdio.h>

#define MAX 10000

int n, m;

int a[MAX], sol[MAX];

void readinput()
{
    int i;

#ifndef ONLINE_JUDGE
    freopen("multiple.in", "r", stdin);
    freopen("multiple.out", "w", stdout);
#endif

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
}

void solve()
{
    int b[MAX], dince[MAX], use[MAX], i, j, suma, testsum;

    for (i = 0; i < n; i++)
    {
        if (a[i] % n == 0)
        {
            printf("1\n%d\n", a[i]);
            return;
        }
        b[i] = -1;
        dince[i] = -1;
    }
    for (i = 0; i < n; i++)
    {
        b[a[i] % n] = a[i];
        dince[a[i] % n] = -1;
        use[a[i] % n] = a[i];
        for (j = n - 1; j >= 0; j--)
            if (b[j] != -1 && b[(j + a[i]) % n] == -1)
            {
                b[(j + a[i]) % n] = (j + a[i]) % n;
                dince[(j + a[i]) % n] = j;
                use[(j + a[i]) % n] = a[i];
            }
    }
    m = 0;
    suma = 0;
    while (1)
    {
        sol[m++] = use[suma];
        if (dince[suma] == -1)
            break;
        suma = dince[suma];
    }
    testsum = 0;
    for (i = 0; i < m; i++)
        testsum = (testsum + sol[i]) % n;
    if (testsum != 0)
        for(;;);
    printf("%d\n", m);
    for (i = 0; i < m; i++)
        printf("%d\n", sol[i]);
}

void writeoutput()
{
#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
}

int main()
{
    readinput();
    solve();
    writeoutput();
    return 0;
}
Re: Have problem, need help.
Posted by I have answers to all your questions :) 25 Feb 2002 23:58
ur output always is a multiple of N but some numbers may be used more
than once, so WA :)