Advertisement
Guest User

asdsadasd

a guest
Apr 8th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. theCache = defaultdict(int)
  4. def isHor(arr, i, j):
  5.     for ci, cj in theCache.keys():
  6.         if i <= ci and j >= cj and theCache[(ci, cj)]:
  7.             return 0
  8.  
  9.     chsum = []
  10.     for k in range(i, j + 1):
  11.         if len(chsum) == 0:
  12.             chsum.append(arr[k])
  13.         else:
  14.             chsum.append(chsum[-1] + arr[k])
  15.  
  16.     lol = defaultdict(int)
  17.     for e in chsum:
  18.         lol[e] += 1
  19.  
  20.     k = 1
  21.     for ii in lol.keys():
  22.         if lol[ii] > 1:
  23.             k = 0
  24.     if lol[0]:
  25.         k = 0
  26.  
  27.     if k == 0:
  28.         theCache[(i, j)] = 1
  29.  
  30.     return k
  31.  
  32. def kek():
  33.     n = int(input())
  34.     arr = list(map(int, input().split()))
  35.  
  36.     countHor = 0
  37.     for i in range(n):
  38.         for j in range(i, n):
  39.             countHor += isHor(arr, i, j)
  40.     #print(theCache)
  41.     print(countHor)
  42.  
  43. def main():
  44.     kek()
  45.  
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement