結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hamray
                         | 
                    
| 提出日時 | 2019-03-17 22:10:12 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,131 ms / 2,000 ms | 
| コード長 | 669 bytes | 
| コンパイル時間 | 589 ms | 
| コンパイル使用メモリ | 72,436 KB | 
| 実行使用メモリ | 37,944 KB | 
| 最終ジャッジ日時 | 2024-07-07 23:33:35 | 
| 合計ジャッジ時間 | 14,944 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <cstring>
#include <functional>
#include <tuple>
using namespace std;
using ll = long long;
vector<ll> v;
int main()
{
    ll N, D; cin >> N >> D;
    
    for(ll i=1; i<=N; ++i){
        for(ll j=1; j<=N; ++j){
            v.push_back(i*i+j*j);
        }
    }
    sort(v.begin(), v.end());
    
    ll ans=0;
    for(int i=1; i<=N; ++i){
        for(int j=1; j<=N; ++j){
            ans += upper_bound(v.begin(), v.end(), D+i*i-j*j) - lower_bound(v.begin(), v.end(), D+i*i-j*j);
        }
    }
    cout << ans << endl;
    
    
    return 0;
}
            
            
            
        
            
hamray