結果

問題 No.45 回転寿司
ユーザー kutsutamakutsutama
提出日時 2018-03-03 23:58:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,203 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 8,644 KB
最終ジャッジ日時 2023-09-18 13:24:18
合計ジャッジ時間 2,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 16 ms
8,184 KB
testcase_23 AC 16 ms
8,292 KB
testcase_24 AC 16 ms
8,304 KB
testcase_25 AC 15 ms
8,200 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 15 ms
8,228 KB
testcase_32 AC 16 ms
8,292 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
v = [int(x) for x in input().split()]

res = 0
stack = []
memo = []
for i in range(n):
    memo.append(set())

stack.append(0)
memo[0].add(v[0])
s = v[0]
res = v[0]
end = False
while not end:
    idx = stack[-1]
    v2 = 0
    v3 = 0
    if idx + 2 < len(v):
        v2 = v[idx + 2]
    if idx + 3 < len(v):
        v3 = v[idx + 3]

    if v2 != 0 and s + v2 not in memo[idx + 2]:
        stack.append(idx + 2)
        memo[idx + 2].add(s + v2)
        res = max(s + v2, res)
        s += v2
    elif v3 != 0 and s + v3 not in memo[idx + 3]:
        stack.append(idx + 3)
        memo[idx + 3].add(s + v3)
        res = max(s + v3, res)
        s += v3
    else:
        for j in range(len(stack)):
            vn = v[stack[-1]]
            idx_n = stack.pop()
            if len(stack) < 1:
                if idx_n == 0 and len(v) >= 2:
                    stack.append(1)
                    s = v[1]
                else:
                    end = True
                break
            idx_p = stack[-1]
            s -= vn
            if (s not in memo[idx_p + 2]) or (s not in memo[idx_p + 3]):
                break

print(res)
0