Skip to content

Instantly share code, notes, and snippets.

@uwi
Created September 30, 2015 10:39
Show Gist options
  • Save uwi/66c6f4427601e39eb5f8 to your computer and use it in GitHub Desktop.
Save uwi/66c6f4427601e39eb5f8 to your computer and use it in GitHub Desktop.
ichyo
import requests as req
def getinput():
r = req.get("http://ichyo.jp/quiz.txt")
a = [int(_) for _ in r.text.split()]
return a
def supply(func, path):
import os.path, json
if not os.path.exists(path):
val = func()
json.dump(val, open(path, 'w'))
else:
val = json.load(open(path, 'r'))
return val
a = supply(getinput, "c:\\temp\\114514.txt")
s = sum(a)
if s % 3 == 0:
tar = s // 3
head1 = 0 # tar
head2 = 0 # 2*tar
sum1 = 0
sum2 = 0
n = len(a)
for i in range(n):
sum1 += a[i]
sum2 += a[i]
while head1 <= i and sum1 > tar:
sum1 -= a[head1]
head1 += 1
while head2 <= i and sum2 > 2*tar:
sum2 -= a[head2]
head2 += 1
if sum1 == tar and sum2 == 2*tar:
print("cut", head2, head1, i+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment