結果

問題 No.800 四平方定理
ユーザー ugis_prog
提出日時 2019-03-17 22:14:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 547 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 77,352 KB
実行使用メモリ 170,036 KB
最終ジャッジ日時 2024-07-07 23:46:55
合計ジャッジ時間 24,680 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 2 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

int main(){
    long N,D;
    cin >> N >> D;

    vector<long> sq;
    unordered_map<int,long> sqsum; 
    for(long i=1;i<=N;i++) sq.emplace_back(i*i);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            sqsum[sq[i]+sq[j]]++;
        }
    }

    long ans = 0;
    for(long x=1;x<=N;x++){
        for(long w=1;w<=N;w++){
            long c = w*w - x*x + D;
            ans += sqsum[c];
        }
    }

    cout << ans << endl;
}
0