結果

問題 No.800 四平方定理
ユーザー ugis_prog
提出日時 2019-03-17 22:32:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,686 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 85,704 KB
実行使用メモリ 95,136 KB
最終ジャッジ日時 2024-07-08 00:35:53
合計ジャッジ時間 21,206 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    for(int y=1;y<=N;y++){
        for(int z=1;z<=N;z++){
            sqsum[y*y+z*z]++;
        }
    }

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

    cout << ans << endl;
}
0