|
|
вернуться в форумHave problem, need help. 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. ur output always is a multiple of N but some numbers may be used more than once, so WA :) |
|
|