結果

問題 No.800 四平方定理
コンテスト
ユーザー yukinon0808
提出日時 2019-03-18 16:40:59
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 454 ms / 2,000 ms
コード長 1,468 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,915 ms
コンパイル使用メモリ 209,780 KB
実行使用メモリ 136,020 KB
最終ジャッジ日時 2026-03-08 16:19:18
合計ジャッジ時間 8,499 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int N, D; cin >> N >> D;

   unordered_map<int,int> cnt;
   cnt.reserve(2*N*N);
   for (int x = 1; x <= N; x++) {
      for (int y = 1; y <= N; y++) {
         cnt[x*x + y*y]++;
      }
   }

   int ans = 0;
   for (int z = 1; z <= N; z++) {
      for (int w = 1; w <= N; w++) {
         if (0 <= w*w - z*z + D && w*w - z*z + D <= 2*N*N) {
            ans += cnt[w*w - z*z + D];
         }
      }
   }
   cout << ans << endl;

   return 0;
}
0