結果

問題 No.2458 Line Up Charged Balls
ユーザー gew1fw
提出日時 2025-06-12 20:53:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,057 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 265,232 KB
最終ジャッジ日時 2025-06-12 20:57:27
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    n = int(input[0])
    q = list(map(int, input[1:n+1]))
    
    prev_dict = {None: 0}
    for num in q:
        curr_dict = {}
        for last_q, sum_val in prev_dict.items():
            # 选项1:不保留当前球
            if last_q in curr_dict:
                if sum_val > curr_dict[last_q]:
                    curr_dict[last_q] = sum_val
            else:
                curr_dict[last_q] = sum_val
            # 选项2:保留当前球
            new_last_q = num
            if last_q is None:
                new_sum = sum_val
            else:
                new_sum = sum_val + last_q * num
            if new_last_q in curr_dict:
                if new_sum > curr_dict[new_last_q]:
                    curr_dict[new_last_q] = new_sum
            else:
                curr_dict[new_last_q] = new_sum
        prev_dict = curr_dict.copy()
    
    if prev_dict:
        print(max(prev_dict.values()))
    else:
        print(0)

if __name__ == "__main__":
    main()
0