Beingamanforever

ABC 384, Problem D

Dec 14th, 2024
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. /**
  2.  *    author:  compounding
  3.  *    created: 2024-12-14 18:07:38
  4.  **/
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
  8. #define NeedForSpeed                  \
  9.     ios_base::sync_with_stdio(false); \
  10.     cin.tie(NULL);                    \
  11.     cout.tie(NULL);
  12. #define int long long
  13. #define all(x) (x).begin(), (x).end()
  14. typedef vector<int> vi;
  15. #define yes cout << "Yes" << endl
  16. #define no cout << "No" << endl
  17. #define endl "\n"
  18.  
  19. void solve()
  20. {
  21.     int n, s;
  22.     cin >> n >> s;
  23.     vi a(n);
  24.     int sum = 0;
  25.     for (int i = 0; i < n; i++)
  26.     {
  27.         cin >> a[i];
  28.         sum += a[i];
  29.     }
  30.     if (s % sum == 0 && s / sum > 0)
  31.     {
  32.         yes;
  33.         return;
  34.     }
  35.     int rem = s % sum, cur = 0;
  36.     map<int, int> seen;
  37.     seen[0] = 1;
  38.     // 2 * n is enough
  39.     for (int i = 0; i < 2 * n; i++)
  40.     {
  41.         cur += a[i % n];
  42.         if (seen.count(cur - rem))
  43.         {
  44.             yes;
  45.             return;
  46.         }
  47.         seen[cur] = 1;
  48.     }
  49.     no;
  50. }
  51.  
  52. signed main()
  53. {
  54.     NeedForSpeed;
  55.     int t = 1;
  56.     // cin >> t;
  57.     while (t--)
  58.         solve();
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment