結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2018-03-03 23:58:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,203 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-05 04:34:54 |
合計ジャッジ時間 | 2,477 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 RE * 28 |
ソースコード
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)