-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathP1356.c
More file actions
38 lines (34 loc) · 843 Bytes
/
P1356.c
File metadata and controls
38 lines (34 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define maxn 10000
#define maxk 100
bool dp[2][maxk];
int mod(int a, int k) {
int res = a % k;
if (res < 0) res += k;
return res;
}
int main() {
int t, n, k, a, cur = 0, pre = 1, tmp;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &k);
scanf("%d", &a);
memset(dp, false, sizeof(dp));
dp[cur][mod(a, k)] = true;
for (int i = 1; i < n; i++) {
scanf("%d", &a);
tmp = cur;
cur = pre;
pre = tmp;
for (int j = 0; j < k; j++) {
dp[cur][j] = dp[pre][mod(j - a, k)] || dp[pre][mod(j + a, k)];
}
}
if (dp[cur][0]) printf("Divisible\n");
else printf("Not divisible\n");
}
exit(0);
}