i am getting wa and wa, i tested all the inputs in the board. i used dp, i cannot find my mistake. if you can, please give me some more test cases. and what is the input for
1
1 5
-5
my program gives Divisible. is it correct, i guess it's correct because in the sample test cases, thay said -14 is divisible by 7.
Code: Select all
#include <stdio.h>
#include <string.h>
int x[10036];
void main()
{
int test, tc, i, k, n, r, f, t, stack[1009], p, add, sub;
bool flag[109];
scanf("%d", &test);
for(tc = 0; tc < test; ++tc)
{
scanf("%d%d", &n, &k);
for(i = 0; i < n; ++i)
{
scanf("%d", &x[i]);
if(x[i] < 0)
x[i] = -x[i];
}
if(n == 1)
{
if(x[0] % k != 0)
puts("Not divisible");
else
puts("Divisible");
continue;
}
r = f = 0;
stack[f++] = x[0] % k;
for(i = 1; i < n; ++i)
{
memset(flag, 0, sizeof(flag));
t = f;
while(r < t)
{
p = stack[r++];
add = (p + x[i]) % k;
sub = (p + k - x[i] % k) % k;
if(!flag[add])
{
flag[add] = 1;
stack[f++] = add;
}
if(!flag[sub])
{
flag[sub] = 1;
stack[f++] = sub;
}
}
}
if(flag[0])
puts("Divisible");
else
puts("Not divisible");
}
}