結果

問題 No.800 四平方定理
コンテスト
ユーザー hedwig100
提出日時 2020-04-24 10:44:42
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,424 ms / 2,000 ms
コード長 368 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 529 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 160,476 KB
最終ジャッジ日時 2026-05-02 15:17:15
合計ジャッジ時間 31,021 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import numpy as np
def main():
    n,d = map(int,input().split())
    square = np.arange(1,n + 1) ** 2
    Add = np.add.outer(square,square).flatten()
    Sub = (square[:,None] - square[None,:]).flatten() + d
    Sub = np.sort(Sub)
    ans = np.searchsorted(Sub,Add,'right') - np.searchsorted(Sub,Add,'left')
    print(ans.sum())
if __name__ =='__main__':
    main()  
0