結果

問題 No.800 四平方定理
ユーザー TiramisterTiramister
提出日時 2019-03-17 23:02:31
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 448 ms
使用メモリ 65,684 KB
最終ジャッジ日時 2023-02-11 11:13:34
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,684 KB
testcase_01 AC 2 ms
4,232 KB
testcase_02 AC 2 ms
3,896 KB
testcase_03 AC 2 ms
4,232 KB
testcase_04 AC 2 ms
3,900 KB
testcase_05 AC 2 ms
3,976 KB
testcase_06 AC 2 ms
4,500 KB
testcase_07 AC 2 ms
4,232 KB
testcase_08 AC 3 ms
4,476 KB
testcase_09 AC 2 ms
4,500 KB
testcase_10 AC 28 ms
34,044 KB
testcase_11 AC 34 ms
37,892 KB
testcase_12 AC 32 ms
37,164 KB
testcase_13 AC 30 ms
35,512 KB
testcase_14 AC 32 ms
37,952 KB
testcase_15 AC 34 ms
37,592 KB
testcase_16 AC 35 ms
38,172 KB
testcase_17 AC 34 ms
38,128 KB
testcase_18 AC 36 ms
38,212 KB
testcase_19 AC 38 ms
38,176 KB
testcase_20 AC 1 ms
3,540 KB
testcase_21 AC 1 ms
3,540 KB
testcase_22 AC 37 ms
38,128 KB
testcase_23 AC 92 ms
65,576 KB
testcase_24 AC 88 ms
65,644 KB
testcase_25 AC 94 ms
65,364 KB
testcase_26 AC 2 ms
3,444 KB
testcase_27 AC 1 ms
3,504 KB
testcase_28 AC 88 ms
65,408 KB
testcase_29 AC 88 ms
65,352 KB
testcase_30 AC 92 ms
65,372 KB
testcase_31 AC 79 ms
60,928 KB
testcase_32 AC 88 ms
65,684 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 (0 <= val && val <= sq(N) * 2) ans += cnt[val];
        }
    }
    cout << ans << endl;
    return 0;
}
0