結果

問題 No.800 四平方定理
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-01 23:00:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 164,896 KB
実行使用メモリ 38,076 KB
最終ジャッジ日時 2023-08-30 04:29:19
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 3 ms
5,088 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 25 ms
20,448 KB
testcase_11 AC 29 ms
21,564 KB
testcase_12 AC 27 ms
22,296 KB
testcase_13 AC 25 ms
19,144 KB
testcase_14 AC 27 ms
20,516 KB
testcase_15 AC 29 ms
22,172 KB
testcase_16 AC 30 ms
20,448 KB
testcase_17 AC 29 ms
20,516 KB
testcase_18 AC 32 ms
24,512 KB
testcase_19 AC 33 ms
24,624 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 32 ms
24,492 KB
testcase_23 AC 79 ms
38,068 KB
testcase_24 AC 70 ms
34,240 KB
testcase_25 AC 75 ms
38,076 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 4 ms
6,968 KB
testcase_28 AC 70 ms
33,984 KB
testcase_29 AC 73 ms
36,228 KB
testcase_30 AC 70 ms
34,232 KB
testcase_31 AC 62 ms
31,988 KB
testcase_32 AC 70 ms
34,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    vector<int> freq(2 * N * N + 1 + D, 0);
    for (int x = 1; x <= N; ++x){
        for (int y = 1; y <= N; ++y){
            ++freq[x*x + y*y];
        }
    }
    long long ans = 0;
    for (int z = 1; z <= N; ++z){
        for (int w = 1; w <= N; ++w){
            int tmp = w * w + D - z * z;
            if (tmp > 0) ans += freq[tmp];
        }
    }
    cout << ans << endl;
    return 0;
}

0