JacobianDet

Hain

Jan 21st, 2021 (edited)
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int ar[200001];
  4. long long arr[200001];
  5. // bool fn(int n,vector<int> arr){
  6. //  int sum=0;
  7. //  for(int i=0;i<n;i++)sum+=arr[i];
  8. //  bool bo=false;int xx=sum%3;
  9. //  map<int,int> mp;
  10. //  for(int i=0;i<n;i++){
  11. //      int x=arr[i]%3;
  12.    
  13. //      mp[x]=1;
  14. //  }
  15. //  if(mp[1]&&mp[2])mp[0]=1;
  16. //  if(mp[xx])return true;
  17. //  return false;
  18. // }
  19.  
  20. bool solve()
  21. {
  22.     int n;
  23.     cin>>n;
  24.     for(int i=1;i<=n;i++)
  25.     {
  26.         cin>>ar[i];
  27.         arr[i] = arr[i-1] + ar[i];
  28.     }
  29.     long long s1 = 0, s3 = 0;
  30.     int i = 1, j = n;
  31.     bool ok = 0;
  32.     while(i < j)
  33.     {
  34.         if(s1 == s3)
  35.         {
  36.             if((arr[j-1] - arr[i]) == s1)
  37.             {
  38.                 ok = 1;
  39.                 break;
  40.             }
  41.             else
  42.             {
  43.                 s1 += ar[i];
  44.                 s3 += ar[j];
  45.                 i++;
  46.                 j--;
  47.             }
  48.         }
  49.         else if(s1 < s3)
  50.         {
  51.             s1 += ar[i];
  52.             i++;
  53.         }
  54.         else
  55.         {
  56.             s3 += ar[j];
  57.             j--;
  58.         }
  59.     }
  60.     return ok;  
  61. }
  62.  
  63. int main() {
  64.     cout<<solve()<<"\n";
  65.     return 0;
  66. }
Add Comment
Please, Sign In to add comment