結果

問題 No.800 四平方定理
ユーザー TiramisterTiramister
提出日時 2019-03-17 23:01:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 578 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 69,052 KB
実行使用メモリ 65,580 KB
最終ジャッジ日時 2023-09-22 09:35:37
合計ジャッジ時間 6,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 39 ms
34,032 KB
testcase_11 AC 42 ms
37,924 KB
testcase_12 AC 39 ms
37,572 KB
testcase_13 AC 35 ms
35,468 KB
testcase_14 AC 37 ms
37,780 KB
testcase_15 AC 41 ms
37,596 KB
testcase_16 AC 39 ms
38,136 KB
testcase_17 AC 37 ms
38,128 KB
testcase_18 AC 44 ms
38,120 KB
testcase_19 AC 43 ms
38,116 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 43 ms
38,368 KB
testcase_23 AC 88 ms
65,488 KB
testcase_24 AC 81 ms
65,504 KB
testcase_25 AC 89 ms
65,580 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 RE -
testcase_28 AC 86 ms
65,144 KB
testcase_29 AC 87 ms
65,336 KB
testcase_30 AC 87 ms
65,120 KB
testcase_31 AC 74 ms
61,132 KB
testcase_32 AC 81 ms
65,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

template <class T>
inline T sq(T a) { return a * a; }

int main() {
    int N, D;
    cin >> N >> D;
    vector<ll> cnt(sq(N) * 2 + 1, 0);
    for (int x = 1; x <= N; ++x) {
        for (int y = 1; y <= N; ++y) {
            ++cnt[sq(x) + sq(y)];
        }
    }

    ll ans = 0;
    for (int z = 1; z <= N; ++z) {
        for (int w = 1; w <= N; ++w) {
            int val = sq(w) - sq(z) + D;
            if (val >= 0) ans += cnt[val];
        }
    }
    cout << ans << endl;
    return 0;
}
0