結果

問題 No.800 四平方定理
ユーザー nominomi
提出日時 2019-03-18 05:06:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,237 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 167,956 KB
実行使用メモリ 36,204 KB
最終ジャッジ日時 2023-09-22 21:54:33
合計ジャッジ時間 17,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 AC 11 ms
4,376 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 12 ms
4,376 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 16 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 557 ms
19,756 KB
testcase_11 AC 571 ms
21,808 KB
testcase_12 AC 624 ms
21,724 KB
testcase_13 AC 457 ms
19,816 KB
testcase_14 AC 503 ms
21,804 KB
testcase_15 AC 634 ms
22,024 KB
testcase_16 AC 508 ms
21,736 KB
testcase_17 AC 504 ms
21,760 KB
testcase_18 AC 715 ms
21,812 KB
testcase_19 AC 713 ms
21,752 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 727 ms
21,808 KB
testcase_23 AC 1,237 ms
36,136 KB
testcase_24 AC 952 ms
36,088 KB
testcase_25 AC 1,218 ms
36,164 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 946 ms
36,064 KB
testcase_29 AC 1,106 ms
36,204 KB
testcase_30 AC 944 ms
36,164 KB
testcase_31 AC 867 ms
34,020 KB
testcase_32 AC 991 ms
36,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

int N, D;
int AB[2222*2222];

signed main() {
  cin >> N >> D;

  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      AB[cnt] = i*i + j*j;
      cnt++;
    }
  }

  sort(AB, AB+cnt);

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      int num = i*i - j*j + D;
      int left = lower_bound(AB, AB+cnt, num) - AB;
      int right = upper_bound(AB, AB+cnt, num) - AB;
      ans += right - left;
    }
  }

  cout << ans << endl;

  return 0;
}
0