結果

問題 No.800 四平方定理
ユーザー finefine
提出日時 2019-03-17 22:46:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 164,048 KB
実行使用メモリ 81,556 KB
最終ジャッジ日時 2023-09-22 08:53:24
合計ジャッジ時間 4,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,848 KB
testcase_01 AC 7 ms
6,284 KB
testcase_02 AC 7 ms
5,780 KB
testcase_03 AC 7 ms
5,892 KB
testcase_04 AC 7 ms
6,120 KB
testcase_05 AC 7 ms
5,856 KB
testcase_06 AC 7 ms
6,188 KB
testcase_07 AC 7 ms
6,488 KB
testcase_08 AC 8 ms
8,296 KB
testcase_09 AC 7 ms
6,112 KB
testcase_10 AC 47 ms
56,816 KB
testcase_11 AC 52 ms
60,956 KB
testcase_12 AC 53 ms
60,720 KB
testcase_13 AC 45 ms
52,632 KB
testcase_14 AC 50 ms
58,908 KB
testcase_15 AC 51 ms
60,692 KB
testcase_16 AC 48 ms
58,684 KB
testcase_17 AC 49 ms
58,620 KB
testcase_18 AC 59 ms
66,852 KB
testcase_19 AC 60 ms
66,852 KB
testcase_20 AC 6 ms
5,532 KB
testcase_21 AC 7 ms
5,452 KB
testcase_22 AC 59 ms
66,808 KB
testcase_23 AC 98 ms
81,496 KB
testcase_24 AC 86 ms
75,536 KB
testcase_25 AC 100 ms
81,556 KB
testcase_26 AC 6 ms
5,348 KB
testcase_27 AC 7 ms
7,732 KB
testcase_28 AC 82 ms
75,604 KB
testcase_29 AC 89 ms
79,464 KB
testcase_30 AC 82 ms
75,536 KB
testcase_31 AC 80 ms
73,304 KB
testcase_32 AC 84 ms
75,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int MAXV = 5000000;

ll cnt1[MAXV + 1], cnt2[MAXV + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            int val = x * x + y * y;
            if (val > MAXV) continue;
            cnt1[val]++;
        }
    }

    for (int w = 1; w <= n; w++) {
        int lim = min(n * n, w * w + d);
        for (int z = 1; z * z <= lim; z++) {
            cnt2[d + w * w - z * z]++;
        }
    }

    ll ans = 0;
    for (int i = 0; i <= MAXV; i++) {
        ans += cnt1[i] * cnt2[i];
    }
    cout << ans << endl;
    return 0;
}
0