結果

問題 No.800 四平方定理
ユーザー nominomi
提出日時 2019-03-18 00:32:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 3,073 ms
コンパイル使用メモリ 163,044 KB
実行使用メモリ 65,092 KB
最終ジャッジ日時 2023-09-22 16:16:07
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,584 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,396 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,908 KB
testcase_07 AC 3 ms
4,408 KB
testcase_08 AC 3 ms
4,692 KB
testcase_09 AC 3 ms
4,572 KB
testcase_10 AC 34 ms
36,120 KB
testcase_11 AC 37 ms
38,172 KB
testcase_12 AC 37 ms
38,164 KB
testcase_13 AC 32 ms
36,276 KB
testcase_14 AC 35 ms
38,148 KB
testcase_15 AC 38 ms
38,168 KB
testcase_16 AC 37 ms
40,232 KB
testcase_17 AC 35 ms
40,452 KB
testcase_18 AC 42 ms
40,220 KB
testcase_19 AC 42 ms
40,220 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 43 ms
40,220 KB
testcase_23 AC 85 ms
65,008 KB
testcase_24 AC 75 ms
64,960 KB
testcase_25 AC 84 ms
64,940 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 77 ms
64,936 KB
testcase_29 AC 79 ms
64,900 KB
testcase_30 AC 76 ms
64,864 KB
testcase_31 AC 69 ms
62,760 KB
testcase_32 AC 78 ms
65,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

int N, D;
int XY[2*2000*2000+100]; // XY[i]: 左辺がiになる組み合わせの数

signed main() {
  cin >> N >> D;
  // 左辺 (x^2 + y^2) の組み合わせを数える
  for (int x = 1; x <= N; x++) {
    for (int y = 1; y <= N; y++) {
      int left = x*x + y*y;
      XY[left]++;
    }
  }

  int ans = 0;
  // 右辺 (w^2 - z^2 + D) の組み合わせを数える
  for (int w = 1; w <= N; w++) {
    for (int z = 1; z <= N; z++) {
      int right = w*w - z*z + D;
      // 左辺の値の範囲は 2 <= (x^2 + y^2) <= 2*N^2
      if (2 <= right and right <= 2*N*N) {
        ans += XY[right];
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0