結果

問題 No.800 四平方定理
ユーザー iqueue02iqueue02
提出日時 2019-11-26 22:18:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,470 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 168,952 KB
実行使用メモリ 34,768 KB
最終ジャッジ日時 2024-04-24 16:18:50
合計ジャッジ時間 21,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,248 KB
testcase_01 AC 19 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 14 ms
5,376 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 23 ms
5,376 KB
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 AC 651 ms
18,904 KB
testcase_11 AC 712 ms
28,116 KB
testcase_12 AC 747 ms
28,116 KB
testcase_13 AC 606 ms
19,536 KB
testcase_14 AC 662 ms
27,984 KB
testcase_15 AC 744 ms
28,116 KB
testcase_16 AC 678 ms
28,112 KB
testcase_17 AC 675 ms
28,116 KB
testcase_18 AC 812 ms
27,992 KB
testcase_19 AC 820 ms
27,988 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 823 ms
28,116 KB
testcase_23 AC 1,470 ms
34,644 KB
testcase_24 AC 1,250 ms
34,644 KB
testcase_25 AC 1,463 ms
34,516 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1,244 ms
34,392 KB
testcase_29 AC 1,365 ms
34,516 KB
testcase_30 AC 1,253 ms
34,424 KB
testcase_31 AC 1,147 ms
32,344 KB
testcase_32 AC 1,293 ms
34,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n, d;
  cin >> n >> d;
  vector<int> wdz, xy;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      wdz.push_back({i*i + d - j*j});
      xy.push_back({i*i + j*j});
    }
  }
  sort(wdz.begin(), wdz.end());
  int m = sz(xy);
  int res = 0;
  for (int i = 0; i < m; i++) {
    auto r = upper_bound(wdz.begin(), wdz.end(), xy[i]) - wdz.begin();
    auto l = lower_bound(wdz.begin(), wdz.end(), xy[i]) - wdz.begin();
    res += r - l; 
  }
  cout << res << endl;
  return 0;
}
0