結果

問題 No.2510 Six Cube Sum Counting
コンテスト
ユーザー detteiuu
提出日時 2026-07-03 22:45:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,425 ms / 4,000 ms
コード長 1,562 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 305 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 484,936 KB
最終ジャッジ日時 2026-07-03 22:46:09
合計ジャッジ時間 30,467 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

X = int(input())

half = X//2
half2 = X//2+X%2

A = []
cntC = [0]*301
for c in range(301):
    for b in range(c+1):
        for a in range(b+1):
            if a*a*a+b*b*b+c*c*c <= half:
                A.append(a*a*a+b*b*b+c*c*c)
                cntC[c] += 1
B = []
cntD = [0]*301
for d in range(301):
    for e in range(d, 301):
        for f in range(e, 301):
            if half2 <= d*d*d+e*e*e+f*f*f <= X:
                B.append(d*d*d+e*e*e+f*f*f)
                cntD[d] += 1

if len(A) >= len(B):
    D = defaultdict(int)
    idx = len(B)-1
    idxA = 300
    while 0 <= idxA and cntC[idxA] == 0: idxA -= 1
    idxB = 300
    while 0 <= idxB and cntD[idxB] == 0: idxB -= 1
    ans = 0
    for i in reversed(range(len(A))):
        while 0 <= idx and idxA <= idxB:
            D[B[idx]] += 1
            cntD[idxB] -= 1
            while 0 <= idxB and cntD[idxB] == 0: idxB -= 1
            idx -= 1
        ans += D[X-A[i]]
        cntC[idxA] -= 1
        while 0 <= idxA and cntC[idxA] == 0: idxA -= 1
else:
    D = defaultdict(int)
    idx = len(A)-1
    idxA = 300
    while 0 <= idxA and cntC[idxA] == 0: idxA -= 1
    idxB = 300
    while 0 <= idxB and cntD[idxB] == 0: idxB -= 1
    ans = 0
    for i in range(len(B)):
        while 0 <= idx and idxA <= idxB:
            D[A[idx]] += 1
            cntC[idxA] -= 1
            while 0 <= idxA and cntC[idxA] == 0: idxA -= 1
            idx -= 1
        ans += D[X-B[i]]
        cntD[idxB] -= 1
        while 0 <= idxB and cntD[idxB] == 0: idxB -= 1

print(ans)
0