18C - Stripe - CodeForces Solution


data structures implementation *1200

Please click on ads to support us..

Python Code:

n = int(input())
li = list(map(int, input().split()))
pref_li = list()
sum_li = 0
cnt = 0
for i in range(n):
    sum_li += li[i]
    pref_li.append(sum_li)
for i in range(n-1):
    if pref_li[n-1]%2 == 0 and pref_li[n-1]/2 == pref_li[i]:
        cnt += 1
print(cnt)

C++ Code:

#include <bits/stdc++.h>

#define endl "\n"
#define loopUP(i, s, e, increament) for(int i = (s); i < (e); i+=increament)
#define loopDOWN(i, s, e, decreament) for(int i = (s); i >= (e); i-=decreament)
#define ll long long

using namespace std;

/*
  A-Z 65-90 to convert to small +32
  a-z 97-122 to convert to capital -32
  0-9 48-57
*/
ll m = 1e9+7;

void solve(){
  int n;
  cin>>n;

  int arr[n+1];
  arr[0]=0;

  loopUP(i, 1, n+1, 1)
    cin>>arr[i];
  
  loopUP(i, 1, n+1, 1)
    arr[i] += arr[i-1];

  int ans=0;
  loopUP(i, 2, n+1, 1){
    if(arr[i-1] == arr[n]-arr[i-1])
    ans++;
  }
  cout<<ans<<endl;
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  // freopen("input", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int t=1;

  //cin>>t;
  //loopUP(i, 1, t+1, 1) solve(i);
  while(t--) {
    solve();
  }
  return 0;
}


Comments

Submit
0 Comments
More Questions

Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations