Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- problem link:https://codeforces.com/contest/577/problem/B
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const int mx = 1e3 + 5;
- int n, m;
- int dp[mx][mx][2];
- int arr[mx];
- int solve(int i, int sum, int flag) {
- if (i >= n) {
- return sum == 0 && flag;
- }
- if (dp[i][sum][flag] != -1)return dp[i][sum][flag];
- int r1 = solve(i + 1, sum, flag);
- int r2 = solve(i + 1, (sum + arr[i]) % m, 1);
- return dp[i][sum][flag] = r1 | r2;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin >> n >> m;
- memset(dp, -1, sizeof(dp));
- for (int i = 0; i < n; ++i) {
- cin >> arr[i];
- arr[i] %= m;
- }
- if (n >= m) {
- cout << "YES" << "\n";
- return 0;
- }
- int res = solve(0, 0, 0);
- if (res) {
- cout << "YES" << "\n";
- } else {
- cout << "NO" << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement