結果

問題 No.800 四平方定理
ユーザー TiramisterTiramister
提出日時 2019-03-17 23:02:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 68,256 KB
実行使用メモリ 65,740 KB
最終ジャッジ日時 2023-09-22 09:37:33
合計ジャッジ時間 3,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,460 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 37 ms
34,136 KB
testcase_11 AC 41 ms
37,932 KB
testcase_12 AC 40 ms
37,168 KB
testcase_13 AC 36 ms
35,536 KB
testcase_14 AC 38 ms
37,920 KB
testcase_15 AC 41 ms
37,660 KB
testcase_16 AC 35 ms
38,412 KB
testcase_17 AC 45 ms
38,080 KB
testcase_18 AC 43 ms
38,080 KB
testcase_19 AC 44 ms
38,228 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 45 ms
38,132 KB
testcase_23 AC 96 ms
65,740 KB
testcase_24 AC 88 ms
65,452 KB
testcase_25 AC 87 ms
65,724 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 83 ms
65,260 KB
testcase_29 AC 84 ms
65,372 KB
testcase_30 AC 82 ms
65,344 KB
testcase_31 AC 78 ms
60,972 KB
testcase_32 AC 88 ms
65,528 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