結果

問題 No.800 四平方定理
ユーザー PocalaPocala
提出日時 2019-03-17 22:34:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 757 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 172,112 KB
実行使用メモリ 92,784 KB
最終ジャッジ日時 2023-09-22 08:21:30
合計ジャッジ時間 19,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 15 ms
4,752 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 AC 11 ms
4,436 KB
testcase_04 AC 11 ms
4,448 KB
testcase_05 AC 13 ms
4,880 KB
testcase_06 AC 16 ms
5,180 KB
testcase_07 AC 19 ms
5,676 KB
testcase_08 AC 22 ms
6,432 KB
testcase_09 AC 15 ms
4,884 KB
testcase_10 AC 1,173 ms
45,828 KB
testcase_11 AC 1,214 ms
44,844 KB
testcase_12 AC 1,371 ms
50,908 KB
testcase_13 AC 858 ms
36,128 KB
testcase_14 AC 975 ms
38,316 KB
testcase_15 AC 1,376 ms
50,628 KB
testcase_16 AC 989 ms
38,664 KB
testcase_17 AC 990 ms
38,736 KB
testcase_18 AC 1,692 ms
59,344 KB
testcase_19 AC 1,661 ms
59,576 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1,562 ms
59,644 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

#define CONTAINS(v, x) (v.find(x) != v.end())

// ===============================================================================

int main() {
  ll n, d;
  cin >> n >> d;
  map<ll, int> right;  //(w+z)(w-z)+D
  for (int w = 1; w <= n; w++) {
    for (int z = 1; z <= n; z++) {
      int r = w * w - z * z + d;
      right[r]++;
      if (r <= 0) break;
    }
  }

  ll ans = 0;

  // x^2+y^2
  for (int x = 1; x <= n; x++) {
    for (int y = x; y <= n; y++) {
      ll l = x * x + y * y;
      if (CONTAINS(right, l)) {
        ans += right.find(l)->second * ((x == y) ? 1 : 2);
      }
    }
  }
  cout << ans << endl;
}
0