結果
| 問題 | No.3331 Consecutive Cubic Sum |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-11-03 01:14:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 5,000 ms |
| コード長 | 1,011 bytes |
| コンパイル時間 | 258 ms |
| コンパイル使用メモリ | 82,224 KB |
| 実行使用メモリ | 85,040 KB |
| 最終ジャッジ日時 | 2025-11-03 01:14:28 |
| 合計ジャッジ時間 | 7,073 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
from collections import deque
def shakutori(a: list, can_expand, expand, shrink, identity):
n = len(a)
res = identity()
hi = -1
for lo in range(n):
if lo > hi:
hi = lo - 1
res = identity()
# 必要な分だけ伸ばす
while hi+1 < n and can_expand(res, a[hi+1]):
res = expand(res, a[hi+1])
hi += 1
if lo <= hi:
yield res, lo, hi
res = shrink(res, a[lo]) # lo をひとつ進める
# res に x を追加できるか
def can_expand(res, x):
return res + pow(x, 3) <= N
# 伸ばす(res に x を追加)
def expand(res, x):
res += pow(x, 3)
return res
# 縮める(res から x を削除)
def shrink(res, x):
res -= pow(x, 3)
return res
N = int(input())
ans = []
a = [x for x in range(1, 10**6+10)]
for res, l, r in shakutori(a, can_expand, expand, shrink, int):
if res == N:
ans.append((l+1, r+1))
print(len(ans))
for l, r in ans:
print(l, r)
norioc