結果
問題 |
No.1318 ABCD quadruplets
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:44:54 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,073 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 63,740 KB |
最終ジャッジ日時 | 2025-06-12 16:45:02 |
合計ジャッジ時間 | 4,640 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 1 -- * 19 |
ソースコード
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()