結果

問題 No.800 四平方定理
コンテスト
ユーザー satou_a_man
提出日時 2019-03-17 21:58:31
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 50 ms / 2,000 ms
+ 597µs
コード長 668 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 861 ms
コンパイル使用メモリ 176,060 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2026-08-11 20:50:14
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll N,D;
  cin>>N>>D;
  vector<int> xy_ans(8000000+1);
  repeat(x,1,N+1) {
    repeat(y,1,N+1) {
      xy_ans[x*x+y*y]++;
    }
  }
  ll ans=0;
  repeat(z,1,N+1) {
    repeat(w,1,N+1) {
      ll c=D+w*w-z*z;
      if(c>=0) {
        ans+=xy_ans[c];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0