Advertisement
Salman_CUET_18

Vasya and Golden Ticket

Apr 7th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define             fastio              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  5. #define             ff                  first
  6. #define             ss                  second
  7. #define             int                 long long
  8. #define             pb                  push_back
  9. #define             pii                 pair<int,int>
  10. #define             print(x)            for(auto it : x) cout<<it<<' '; cout<<'\n';
  11. #define             debug(x)            cout<< #x << " ---> " << x << "\n"
  12. #define             p(x,y)              fixed<<setprecision(y)<<x
  13. #define             yes                 cout << "YES" << endl;
  14. #define             no                  cout << "NO" << endl;
  15. #define             mod                 1000000007
  16. #define             inf                 2000000009
  17. #define             PI                  (acos(-1))
  18. #define             eps                 (1e-8)
  19. #define             clear(x)            memset(x,0,sizeof(x));
  20.  
  21.  
  22. main()
  23. {
  24.     fastio;
  25. #ifndef ONLINE_JUDGE
  26.     freopen("input.txt", "r", stdin);
  27.     freopen("output.txt", "w", stdout);
  28. #endif
  29.  
  30.     int n;
  31.     string s;
  32.     cin >> n >> s;
  33.     int totalsum = 0;
  34.     for(int i = 0; i < n; i++) totalsum += s[i] - '0';
  35.     // debug(totalsum);
  36.     string ans = "NO";
  37.     for(int i = 2; i <= n; i++)
  38.     {
  39.         if(totalsum % i == 0)
  40.         {
  41.             int testsum = 0, cnt = 0;
  42.             for(int j = 0; j < n; j++)
  43.             {
  44.                 testsum += s[j] - '0';
  45.                 if(testsum == (totalsum / i))
  46.                 {
  47.                     testsum = 0;
  48.                     cnt++;
  49.                 }
  50.             }
  51.             if(cnt == i)
  52.             {
  53.                 ans = "YES";
  54.                 break;
  55.             }
  56.         }
  57.     }
  58.     cout << ans << endl;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement