結果

問題 No.1318 ABCD quadruplets
ユーザー lam6er
提出日時 2025-04-15 23:35:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,297 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 81,612 KB
実行使用メモリ 78,876 KB
最終ジャッジ日時 2025-04-15 23:36:38
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 2 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

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

    # Precompute ab_freq: X -> {A: count}
    ab_freq = defaultdict(lambda: defaultdict(int))
    for a in range(M+1):
        for b in range(M+1):
            X = a + b
            A = a*a + a*b + b*b
            ab_freq[X][A] += 1

    # Precompute cd_freq: Y -> {B: count}
    cd_freq = defaultdict(lambda: defaultdict(int))
    for c in range(M+1):
        for d in range(M+1):
            Y = c + d
            B = c*c + c*d + d*d
            cd_freq[Y][B] += 1

    ans = [0] * (N + 1)

    # Iterate over all possible X and Y pairs
    for X in ab_freq:
        for Y in cd_freq:
            XY = X * Y
            if XY > N:
                continue
            # Iterate through all A and B for this X and Y
            for A, count_A in ab_freq[X].items():
                max_B = N - A - XY
                if max_B < 0:
                    continue
                for B, count_B in cd_freq[Y].items():
                    if B > max_B:
                        continue
                    k = A + XY + B
                    if k <= N:
                        ans[k] += count_A * count_B

    for k in range(N+1):
        print(ans[k])

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