結果

問題 No.800 四平方定理
ユーザー ScottShelbyScottShelby
提出日時 2020-08-24 23:55:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 163,992 KB
実行使用メモリ 65,920 KB
最終ジャッジ日時 2024-04-24 04:02:22
合計ジャッジ時間 4,630 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
65,920 KB
testcase_01 AC 53 ms
65,664 KB
testcase_02 AC 53 ms
65,792 KB
testcase_03 AC 53 ms
65,792 KB
testcase_04 AC 52 ms
65,664 KB
testcase_05 AC 52 ms
65,664 KB
testcase_06 AC 53 ms
65,792 KB
testcase_07 AC 54 ms
65,920 KB
testcase_08 AC 54 ms
65,792 KB
testcase_09 AC 52 ms
65,792 KB
testcase_10 AC 69 ms
65,792 KB
testcase_11 AC 71 ms
65,792 KB
testcase_12 AC 72 ms
65,664 KB
testcase_13 AC 69 ms
65,792 KB
testcase_14 AC 71 ms
65,792 KB
testcase_15 AC 73 ms
65,920 KB
testcase_16 AC 70 ms
65,664 KB
testcase_17 AC 73 ms
65,664 KB
testcase_18 AC 75 ms
65,792 KB
testcase_19 AC 73 ms
65,920 KB
testcase_20 AC 51 ms
65,920 KB
testcase_21 AC 51 ms
65,664 KB
testcase_22 AC 73 ms
65,792 KB
testcase_23 AC 107 ms
65,920 KB
testcase_24 AC 103 ms
65,664 KB
testcase_25 AC 107 ms
65,664 KB
testcase_26 AC 51 ms
65,920 KB
testcase_27 AC 51 ms
65,664 KB
testcase_28 AC 101 ms
65,664 KB
testcase_29 AC 103 ms
65,920 KB
testcase_30 AC 100 ms
65,664 KB
testcase_31 AC 96 ms
65,664 KB
testcase_32 AC 103 ms
65,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
const int MAXV = 2000 * 2000 + 2000 * 2000 + 1;
int main() {
  int n, d;
  cin >> n >> d;

  vector<int> a(MAXV), b(MAXV);

  for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) {
    int v = i * i + j * j;
    a[v]++;
  }

  for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) {
    int v = i * i - j * j + d;
    if (v >= MAXV || v < 0) continue;
    b[v]++;
  }

  ll ans = 0;
  rep(i, MAXV) {
    ans += a[i] * b[i];
  }

  cout << ans << endl;

}
0