結果

問題 No.2479 Sum of Squares
ユーザー ntuda
提出日時 2025-02-11 16:33:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 278,000 KB
最終ジャッジ日時 2025-02-11 16:34:31
合計ジャッジ時間 38,752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other RE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100050)

def search(x):  # a * a <= y を満たす最大のaを求める
    lb = 1
    ub = x + 1
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if mid * mid <= x:
            lb = mid
        else:
            ub = mid
    return lb

def dfs(x,y,n):
    global ans,tmp,ans2
    if n >= ans:
        return
    if x == 0:
        print(n)
        print(*tmp)
        exit()
        return
    if y == 1:
        if n + x < 16:
            print(n + x)
            print(*(tmp + [1] * x))
            exit()
        return
    ret = 0
    if x - y * y >= 0:
        tmp.append(y)
        dfs(x - y * y, y, n + 1)
        tmp.pop()
    y -= 1
    if x // (y * y) + n < 16:
        dfs(x, y, n)

tmp = []
ans2 = []
S = int(input())
ans = S + 1
y = search(S)
dfs(S,y,0)
print(ans)
ans2 = [i*i for i in ans2]
print(*ans2)
0