提出 #21185066


ソースコード 拡げる

import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def odd(A):
    base=np.array(A[1::2],dtype=np.int64) #基準状態 
    other=np.array(A[::2],dtype=np.int64) #基準状態以外
    left=np.cumsum(other[:-1]-base) #基準状態から左i個を左にずらした時の増分を累積和で求める。
    left=np.insert(left,0,0) #0個ずらした時の増分(0)を挿入
    right=np.cumsum(other[:0:-1]-base[::-1])[::-1] #基準状態から右i個を右にずらした時の増分を累積和で求める。ただし、配列をひっくり返して保存。
    right=np.append(right,0) #0個ずらした時の増分(0)を挿入
    tmp=np.max(np.maximum.accumulate(left)+right) #基準状態からの増分の最大値を、leftの累積最大値とrightの和の最大値で求める。
    return tmp+np.sum(base) #増分の最大値と、基準状態の和を出力

def main():
    n=int(input())
    A=list(map(int, input().split()))
    if n%2==1:
        print(odd(A))
    else:
        print(odd(A+[-3*10**14]))


if __name__ == '__main__':
    main()

提出情報

提出日時
問題 F - Select Half
ユーザ ansain
言語 Python (3.8.2)
得点 600
コード長 1123 Byte
結果 AC
実行時間 184 ms
メモリ 50968 KiB

ジャッジ結果

セット名 Sample All after_contest
得点 / 配点 0 / 0 600 / 600 0 / 0
結果
AC × 4
AC × 18
AC × 2
セット名 テストケース
Sample sample_01, sample_02, sample_03, sample_04
All random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, sample_01, sample_02, sample_03, sample_04, hand_01, hand_02, max_01, max_02
after_contest after_contest_01, after_contest_02
ケース名 結果 実行時間 メモリ
after_contest_01 AC 180 ms 49372 KiB
after_contest_02 AC 172 ms 49088 KiB
hand_01 AC 110 ms 27076 KiB
hand_02 AC 107 ms 27120 KiB
max_01 AC 173 ms 49416 KiB
max_02 AC 180 ms 49136 KiB
random_01 AC 184 ms 49172 KiB
random_02 AC 180 ms 49544 KiB
random_03 AC 177 ms 49432 KiB
random_04 AC 180 ms 49008 KiB
random_05 AC 178 ms 49268 KiB
random_06 AC 176 ms 49368 KiB
random_07 AC 179 ms 49388 KiB
random_08 AC 175 ms 49360 KiB
random_09 AC 175 ms 50968 KiB
random_10 AC 171 ms 49420 KiB
sample_01 AC 109 ms 27036 KiB
sample_02 AC 112 ms 26628 KiB
sample_03 AC 114 ms 27060 KiB
sample_04 AC 112 ms 27116 KiB