結果

問題 No.800 四平方定理
ユーザー FromBooskaFromBooska
提出日時 2023-03-03 05:04:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 191,208 KB
最終ジャッジ日時 2023-10-17 23:35:46
合計ジャッジ時間 6,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
65,204 KB
testcase_01 AC 55 ms
66,464 KB
testcase_02 AC 55 ms
65,784 KB
testcase_03 AC 55 ms
65,992 KB
testcase_04 AC 54 ms
65,688 KB
testcase_05 AC 54 ms
65,936 KB
testcase_06 AC 55 ms
66,928 KB
testcase_07 AC 61 ms
66,260 KB
testcase_08 AC 54 ms
66,928 KB
testcase_09 AC 55 ms
66,568 KB
testcase_10 AC 160 ms
127,040 KB
testcase_11 AC 164 ms
135,768 KB
testcase_12 AC 166 ms
134,560 KB
testcase_13 AC 144 ms
131,008 KB
testcase_14 AC 152 ms
135,768 KB
testcase_15 AC 169 ms
135,304 KB
testcase_16 AC 156 ms
136,520 KB
testcase_17 AC 158 ms
136,520 KB
testcase_18 AC 179 ms
136,232 KB
testcase_19 AC 178 ms
136,328 KB
testcase_20 AC 40 ms
53,452 KB
testcase_21 AC 41 ms
55,500 KB
testcase_22 AC 178 ms
136,520 KB
testcase_23 AC 309 ms
190,520 KB
testcase_24 AC 268 ms
191,208 KB
testcase_25 AC 277 ms
190,832 KB
testcase_26 AC 39 ms
53,452 KB
testcase_27 AC 38 ms
53,452 KB
testcase_28 AC 256 ms
190,576 KB
testcase_29 AC 269 ms
190,952 KB
testcase_30 AC 258 ms
190,704 KB
testcase_31 AC 234 ms
182,008 KB
testcase_32 AC 267 ms
191,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 公式解説より
# 2重ループは可能、を押し進めるべきだった
# x, yで作れる数を全探索
# w, D, zで作れる数を全探索
# その組合せ数が答え
# TLEする、defaultdictより配列の方が高速なのか?

N, D = map(int, input().split())
from collections import defaultdict
xy = [0]*(2*N**2+1)
for x in range(1, N+1):
    for y in range(1, N+1):
        calc = x**2+y**2
        xy[calc] += 1
wDz = [0]*(2*N**2+1)
for w in range(1, N+1):
    for z in range(1, N+1):
        calc = w**2+D-z**2
        if 0 < calc <= 2*N**2+1:
            wDz[calc] += 1
        
ans = 0
for i in range(1, 2*N**2+1):
    ans += xy[i]*wDz[i]
print(ans)
0