結果

問題 No.3407 Birds-of-Paradise' Christmas Live
コンテスト
ユーザー sasa8uyauya
提出日時 2025-12-29 16:59:07
言語 PyPy3
(7.3.17)
結果
WA  
実行時間 -
コード長 1,563 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 330 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 308,908 KB
最終ジャッジ日時 2025-12-29 16:59:27
合計ジャッジ時間 19,048 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 14 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n=int(input())
t=list(map(int,input().split()))
p=[]
x=0
for i in range(n):
  x+=t[i]
  p+=[[x,(i+1)%2]]
if p[0][0]==0:
  p=p[1:]
p1=p[:]
n=int(input())
t=list(map(int,input().split()))
p=[]
x=0
for i in range(n):
  x+=t[i]
  p+=[[x,(i+1)%2]]
if p[0][0]==0:
  p=p[1:]
p2=p[:]
t=sorted(set(t for t,f in p1+p2))
p=[]
l=0
for x,f in p1:
  while l<len(t) and t[l]<=x:
    p+=[[t[l],f]]
    l+=1
p1=p[:]
p=[]
l=0
for x,f in p2:
  while l<len(t) and t[l]<=x:
    p+=[[t[l],f]]
    l+=1
p2=p[:]
p=[]
x=0
for i in range(len(t)):
  w=t[i]-x
  f=p1[i][1]*2+p2[i][1]
  if len(p)==0 or p[-1][1]!=f:
    p+=[[0,f]]
  p[-1][0]+=w
  x=t[i]
l=0
while l<len(p):
  if p[l][1] in [1,2]:
    f=p[l][1]
    r=l
    while r+1<len(p) and (p[r+1][1] in [f,3]):
      r+=1
    if p[r][1]==3:
      r-=1
    p[l:r+1]=[[sum(w for w,f in p[l:r+1]),f]]
    l=r
  l+=1
p=[[1,0]]+p+[[1,0]]
l=0
while l<len(p):
  if p[l][1]==3 and p[l-1][1]==0 and p[l+1][1]!=0:
    p[l:l+2]=[[p[l][0]+p[l+1][0],p[l+1][1]]]
  l+=1
p=p[::-1]
l=0
while l<len(p):
  if p[l][1]==3 and p[l-1][1]==0 and p[l+1][1]!=0:
    p[l:l+2]=[[p[l][0]+p[l+1][0],p[l+1][1]]]
  l+=1
p=p[::-1]
a=0
l=0
while l<len(p):
  if p[l][1]!=0:
    r=l
    while r+1<len(p) and p[r+1][1]!=0:
      r+=1
    q=[0,0]
    q[1]=p[l][0]**2
    for i in range(1,r-l+1):
      nq=[0,0]
      f=p[i+l][1]
      ff=p[i-1+l][1]
      nq[0]=max(q[1],q[0]+p[i-1+l][0]**2)
      nq[1]=max(q[1],q[0]+p[i-1+l][0]**2)+p[i+l][0]**2
      if f==3 or ff==3:
        nq[1]=max(nq[1],q[0]+(p[i-1+l][0]+p[i+l][0])**2)
      q=nq
    a+=q[1]
    l=r
  l+=1
print(a)
0