結果

問題 No.800 四平方定理
ユーザー oxyshower
提出日時 2019-04-06 17:41:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,580 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 163,796 KB
実行使用メモリ 65,984 KB
最終ジャッジ日時 2024-06-24 09:31:24
合計ジャッジ時間 22,644 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,D; cin >> N >> D;
  vector<int> xy,zw;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      xy.push_back(i*i + j*j);
      zw.push_back(i*i - j*j);
    }
  }
  sort(zw.begin(),zw.end());

  int ans = 0;
  for(auto p : xy){
    auto r = upper_bound(zw.begin(),zw.end(),D - p);
    auto l = lower_bound(zw.begin(),zw.end(),D - p);
    ans += r - l;
  }
  cout << ans << endl;

  return 0;
}
0