結果

問題 No.1318 ABCD quadruplets
ユーザー gew1fw
提出日時 2025-06-12 21:30:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,073 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 266,760 KB
最終ジャッジ日時 2025-06-12 21:30:40
合計ジャッジ時間 4,518 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    N, M = map(int, sys.stdin.readline().split())

    # We'll use two dictionaries to keep track of the state transitions
    # Each state is (s, q): sum and sum of squares
    # We'll process each variable (a, b, c, d) step by step

    # Initialize DP with the first variable (a)
    dp = defaultdict(int)
    dp[(0, 0)] = 1  # initial state before processing any variable

    # Process each of the four variables
    for _ in range(4):
        new_dp = defaultdict(int)
        for (s, q), cnt in dp.items():
            for x in range(0, M+1):
                new_s = s + x
                new_q = q + x * x
                new_dp[(new_s, new_q)] += cnt
        dp = new_dp

    # Now, for each (s, q) in dp, compute E and update the result
    result = [0] * (N + 1)
    for (s, q), cnt in dp.items():
        E = (s * s + q) // 2
        if E <= N:
            result[E] += cnt

    # Output the result from 0 to N
    for n in range(N + 1):
        print(result[n])

if __name__ == "__main__":
    main()
0