結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tottoripaper
                         | 
                    
| 提出日時 | 2019-03-18 18:19:21 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 638 ms / 2,000 ms | 
| コード長 | 944 bytes | 
| コンパイル時間 | 1,678 ms | 
| コンパイル使用メモリ | 173,252 KB | 
| 実行使用メモリ | 34,756 KB | 
| 最終ジャッジ日時 | 2024-07-18 13:07:32 | 
| 合計ジャッジ時間 | 11,349 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = std::int64_t;
using P = std::tuple<int,int>;
int N, D;
std::vector<int> v, w;
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> D;
    for(int i=1;i<=N;++i){
        for(int j=1;j<=N;++j){
            v.emplace_back(i * i + j * j);
            w.emplace_back(- i * i + j * j + D);
        }
    }
    std::sort(v.begin(), v.end());
    std::sort(w.begin(), w.end());
    ll cnt = 0;
    int i = 0, j = 0;
    for(int s : v){
        while(i < w.size() && w[i] < s){
            i += 1;
        }
        j = i;
        while(j < w.size() && w[j] <= s){
            j += 1;
        }
        if(i < w.size() && w[i] == s){
            cnt += j - i;
        }
    }
    std::cout << cnt << std::endl;
}
            
            
            
        
            
tottoripaper