Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- #define ll long long
- #define cy cout << "YES"
- #define cn cout << "NO"
- #define nl "\n"
- #define fi first
- #define se second
- #define cin(v) for (int i = 0; i < n, cin >> v[i]; i++)
- #define cout(v) for (int i = 0; i < v.size(), cout << v[i] << " "; i++)
- #define all(v) v.begin(), v.end()
- #define sz(s) s.size()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int n, k;
- vector<int> a;
- vector<vector<int>> dp;
- int fix(int x)
- return (x % k + k) % k;
- bool isdiv(int idx, int sum)
- {
- if (idx == n)
- return sum == 0;
- int &ret = dp[idx][sum];
- if (~ret)
- return ret;
- return (ret = isdiv(idx + 1, fix(sum - a[idx])) || isdiv(idx + 1, fix(sum + a[idx])));
- }
- void solve()
- {
- cin >> n >> k;
- a.resize(n);
- cin(a);
- dp.assign(n, vector<int>(k, -1));
- cout << (isdiv(1, fix(a[0]))? "Divisible":"Not divisible")<< nl;
- }
- int main()
- {
- sherry();
- int t = 1;
- cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement