結果

問題 No.800 四平方定理
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-08-18 08:47:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 166,192 KB
実行使用メモリ 34,400 KB
最終ジャッジ日時 2023-08-02 04:42:44
合計ジャッジ時間 4,330 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 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 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 24 ms
18,436 KB
testcase_11 AC 27 ms
20,548 KB
testcase_12 AC 25 ms
20,356 KB
testcase_13 AC 22 ms
19,152 KB
testcase_14 AC 23 ms
20,500 KB
testcase_15 AC 23 ms
20,108 KB
testcase_16 AC 26 ms
20,696 KB
testcase_17 AC 26 ms
20,792 KB
testcase_18 AC 30 ms
20,372 KB
testcase_19 AC 30 ms
20,548 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 27 ms
20,820 KB
testcase_23 AC 67 ms
34,296 KB
testcase_24 AC 62 ms
34,280 KB
testcase_25 AC 65 ms
34,400 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 63 ms
34,084 KB
testcase_29 AC 62 ms
34,328 KB
testcase_30 AC 61 ms
34,328 KB
testcase_31 AC 51 ms
31,956 KB
testcase_32 AC 59 ms
34,256 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