Guest User

Untitled

a guest
Sep 10th, 2015
5,419
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4.  
  5. #include <vector>
  6. #include <set>
  7. #include <bitset>
  8. #include <map>
  9. #include <deque>
  10. #include <string>
  11.  
  12. #include <algorithm>
  13. #include <numeric>
  14.  
  15. #include <cstdio>
  16. #include <cassert>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <ctime>
  20. #include <cmath>
  21.  
  22. #define pb push_back
  23. #define pbk pop_back
  24. #define mp make_pair
  25. #define fs first
  26. #define sc second
  27. #define all(x) (x).begin(), (x).end()
  28. #define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
  29. #define len(a) ((int) (a).size())
  30.  
  31. #ifdef CUTEBMAING
  32. #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  33. #else
  34. #define eprintf(...) 42
  35. #endif
  36.  
  37. using namespace std;
  38.  
  39. typedef long long int64;
  40. typedef long double ld;
  41. typedef unsigned long long lint;
  42.  
  43. const int inf = (1 << 30) - 1;
  44. const int64 linf = (1ll << 62) - 1;
  45.  
  46. int main() {
  47.     int n, p; cin >> n >> p;
  48.     n = min(n, p);
  49.     vector<int> a(n);
  50.     for (int i = 0; i < n; i++) {
  51.         cin >> a[i];
  52.         a[i] %= p;
  53.     }
  54.     vector<int> parent(p, -1), newParent(p, -1);
  55.     for (int t = 0; t < n && parent[0] == -1; t++) {
  56.         int v = a[t];
  57.         copy(all(parent), newParent.begin());
  58.         if (newParent[v] == -1) {
  59.             newParent[v] = t;
  60.         }
  61.         for (int i = 0; i < p; i++) {
  62.             if (parent[i] != -1 && parent[(i + v) % p] == -1) {
  63.                 newParent[(i + v) % p] = t;
  64.             }
  65.         }
  66.         copy(all(newParent), parent.begin());
  67.     }
  68.     if (parent[0] == -1) {
  69.         puts("NO");
  70.     } else {
  71.         puts("YES");
  72.     }
  73.     return 0;
  74. }
RAW Paste Data