結果

問題 No.800 四平方定理
ユーザー amesyu
提出日時 2019-10-05 10:06:30
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,403 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 90,372 KB
実行使用メモリ 68,016 KB
最終ジャッジ日時 2024-10-05 06:48:28
合計ジャッジ時間 19,680 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
    long long n, m;
    long long t = 0;
    long long ans = 0;
    cin >> n >> m;
    vector<long long> xy;
    vector<long long> wz;
    for(long long i=1;i<n+1;i++) {
        for(long long j=1;j<n+1;j++) {
            xy.push_back(i*i + j*j);
            wz.push_back(i*i - j*j + m);
            t+=1;
        }
    }
    sort(wz.begin(), wz.end());
    for(int i=0;i<xy.size();i++) {
        long long low = distance(wz.begin(), lower_bound(wz.begin(), wz.end(), xy[i]));
        long long up = distance(wz.begin(), upper_bound(wz.begin(), wz.end(), xy[i]));
        ans += up-low;
    }
    cout << ans <<  endl;
}
0