結果

問題 No.800 四平方定理
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-08-18 08:47:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 164,420 KB
実行使用メモリ 34,532 KB
最終ジャッジ日時 2024-04-20 04:48:19
合計ジャッジ時間 3,043 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 16 ms
18,664 KB
testcase_11 AC 17 ms
20,576 KB
testcase_12 AC 17 ms
20,352 KB
testcase_13 AC 15 ms
19,388 KB
testcase_14 AC 17 ms
20,796 KB
testcase_15 AC 16 ms
20,756 KB
testcase_16 AC 15 ms
20,752 KB
testcase_17 AC 15 ms
20,624 KB
testcase_18 AC 15 ms
20,820 KB
testcase_19 AC 16 ms
20,764 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 16 ms
20,980 KB
testcase_23 AC 34 ms
34,532 KB
testcase_24 AC 30 ms
34,448 KB
testcase_25 AC 32 ms
34,360 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 31 ms
34,332 KB
testcase_29 AC 31 ms
34,360 KB
testcase_30 AC 30 ms
34,372 KB
testcase_31 AC 26 ms
32,136 KB
testcase_32 AC 28 ms
34,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    int n, d;
    cin >> n >> d;
    vector<int> c(n * n * 2 + 1);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            c[i * i + j * j]++;
        }
    }


    ll ans = 0;
    for(int w = 1; w <= n; w++) {
        for(int z = 1; z <= n; z++) {
            int k = d + w * w - z * z;
            if(k < 0 || k >= (int)c.size())continue;
            ans += c[k];
        }
    }
    cout << ans << endl;

}
0