結果

問題 No.800 四平方定理
ユーザー simansiman
提出日時 2022-04-05 09:02:25
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 105,820 KB
実行使用メモリ 128,548 KB
最終ジャッジ日時 2023-08-17 12:21:38
合計ジャッジ時間 4,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
128,432 KB
testcase_01 AC 34 ms
128,464 KB
testcase_02 AC 34 ms
128,440 KB
testcase_03 AC 34 ms
128,428 KB
testcase_04 AC 34 ms
128,432 KB
testcase_05 AC 34 ms
128,436 KB
testcase_06 AC 34 ms
128,508 KB
testcase_07 AC 35 ms
128,440 KB
testcase_08 AC 35 ms
128,488 KB
testcase_09 AC 34 ms
128,544 KB
testcase_10 AC 65 ms
128,488 KB
testcase_11 AC 71 ms
128,512 KB
testcase_12 AC 70 ms
128,308 KB
testcase_13 AC 65 ms
128,424 KB
testcase_14 AC 67 ms
128,376 KB
testcase_15 AC 71 ms
128,512 KB
testcase_16 AC 71 ms
128,440 KB
testcase_17 AC 67 ms
128,516 KB
testcase_18 AC 72 ms
128,372 KB
testcase_19 AC 71 ms
128,460 KB
testcase_20 AC 32 ms
128,548 KB
testcase_21 AC 33 ms
128,372 KB
testcase_22 AC 73 ms
128,360 KB
testcase_23 AC 113 ms
128,456 KB
testcase_24 AC 104 ms
128,464 KB
testcase_25 AC 113 ms
128,456 KB
testcase_26 AC 32 ms
128,476 KB
testcase_27 AC 33 ms
128,496 KB
testcase_28 AC 105 ms
128,440 KB
testcase_29 AC 108 ms
128,492 KB
testcase_30 AC 104 ms
128,356 KB
testcase_31 AC 98 ms
128,488 KB
testcase_32 AC 104 ms
128,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 2000;
const int MAX_D = 1000000;

ll cnt1[2 * MAX_N * MAX_N + 10];
ll cnt2[2 * MAX_N * MAX_N + 10];

int main() {
  int N, D;
  cin >> N >> D;
  memset(cnt1, 0, sizeof(cnt1));
  memset(cnt2, 0, sizeof(cnt2));

  for (int x = 1; x <= N; ++x) {
    for (int y = 1; y <= N; ++y) {
      int v = x * x + y * y;
      cnt1[v]++;
    }
  }

  for (int w = 1; w <= N; ++w) {
    for (int z = 1; z <= N; ++z) {
      int v = w * w - z * z + D;
      if (v <= 0) continue;
      cnt2[v]++;
    }
  }

  ll ans = 0;

  for (int v = 1; v <= 2 * N * N; ++v) {
    ans += cnt1[v] * cnt2[v];
  }

  cout << ans << endl;

  return 0;
}
0