結果

問題 No.800 四平方定理
ユーザー nominomi
提出日時 2019-03-18 00:39:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 165,184 KB
実行使用メモリ 106,192 KB
最終ジャッジ日時 2023-09-22 16:17:35
合計ジャッジ時間 3,845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,740 KB
testcase_01 AC 3 ms
8,060 KB
testcase_02 AC 3 ms
5,792 KB
testcase_03 AC 2 ms
5,900 KB
testcase_04 AC 3 ms
5,800 KB
testcase_05 AC 2 ms
6,176 KB
testcase_06 AC 3 ms
8,140 KB
testcase_07 AC 4 ms
8,244 KB
testcase_08 AC 3 ms
7,628 KB
testcase_09 AC 3 ms
8,316 KB
testcase_10 AC 41 ms
56,612 KB
testcase_11 AC 45 ms
60,792 KB
testcase_12 AC 45 ms
62,720 KB
testcase_13 AC 39 ms
54,540 KB
testcase_14 AC 43 ms
58,604 KB
testcase_15 AC 46 ms
62,736 KB
testcase_16 AC 44 ms
58,728 KB
testcase_17 AC 43 ms
58,628 KB
testcase_18 AC 51 ms
66,824 KB
testcase_19 AC 49 ms
66,916 KB
testcase_20 AC 2 ms
5,388 KB
testcase_21 AC 2 ms
5,448 KB
testcase_22 AC 51 ms
66,864 KB
testcase_23 AC 98 ms
106,192 KB
testcase_24 AC 90 ms
98,404 KB
testcase_25 AC 99 ms
105,796 KB
testcase_26 AC 2 ms
5,512 KB
testcase_27 AC 2 ms
5,652 KB
testcase_28 AC 89 ms
99,772 KB
testcase_29 AC 91 ms
103,680 KB
testcase_30 AC 87 ms
99,596 KB
testcase_31 AC 81 ms
93,496 KB
testcase_32 AC 89 ms
99,596 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になる組み合わせの数
int WZ[2*2000*2000+100]; // WZ[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]++;
    }
  }

  // 右辺 (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;
      // 式が複雑なので判定を入れておく
      if (right >= 2 and right <= 2*N*N) {
        WZ[right]++;
      }
    }
  }

  int ans = 0;
  // (値がiとなる左辺の場合の数 * 値がiとなる右辺の場合の数)を足し合わせる
  for (int i = 2; i <= 2*N*N; i++) {
    ans += XY[i] * WZ[i];
  }

  cout << ans << endl;

  return 0;
}
0