Codeforces Round 918 (Div. 4) 1915E. Romantic Glasses Solution



Problem Link :  https://codeforces.com/contest/1915/problem/E

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ;
  11. cin >> n ;
  12. int a[n+2] ;
  13. for(int i = 1 ; i <= n ; i++){
  14. cin >> a[i] ;
  15. }
  16. map<long long ,long long >mp ;
  17. long long sum = 0 ;
  18. mp[sum] = 1 ;
  19. bool ok = false ;
  20. for ( int i = 1 ; i <= n ; i++ ){
  21. if (i%2){
  22. sum +=a[i] ;
  23. }
  24. else{
  25. sum -=a[i] ;
  26. }
  27. if (mp[sum]){
  28. ok = true ;
  29. break ;
  30. }
  31. mp[sum] = 1 ;
  32. }
  33. if (ok) cout <<"YES\n";
  34. else cout <<"NO\n";
  35. }
  36. return 0 ;
  37. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.