結果

問題 No.800 四平方定理
ユーザー dsaito11
提出日時 2019-07-03 19:44:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,457 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 90,716 KB
実行使用メモリ 82,856 KB
最終ジャッジ日時 2024-09-16 04:55:40
合計ジャッジ時間 19,791 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>


#define INF 10e15
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;


int main() {
    long long int n, d;
    cin >> n >> d;

    vector<long long int> x, y;

    long long int i, j;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            x.push_back(i*i + j*j);
            
            if(i*i - j*j + d >= 0){
                y.push_back(i*i - j*j + d);
            }
        }
    }

    sort(y.begin(), y.end());

    long long int count = 0;
    for(i = 0; i < x.size(); i++){
        count += upper_bound(y.begin(), y.end(), x[i]) - lower_bound(y.begin(), y.end(), x[i]);
    }

    cout << count << endl;
}


0