結果

問題 No.800 四平方定理
ユーザー ugis_progugis_prog
提出日時 2019-03-17 22:32:33
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 1,466 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 631 ms
使用メモリ 94,900 KB
最終ジャッジ日時 2023-02-11 09:20:38
合計ジャッジ時間 19,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 6 ms
4,208 KB
testcase_01 AC 11 ms
5,576 KB
testcase_02 AC 8 ms
4,328 KB
testcase_03 AC 8 ms
4,572 KB
testcase_04 AC 7 ms
4,440 KB
testcase_05 AC 9 ms
4,548 KB
testcase_06 AC 12 ms
5,560 KB
testcase_07 AC 12 ms
5,528 KB
testcase_08 AC 8 ms
4,448 KB
testcase_09 AC 10 ms
4,740 KB
testcase_10 AC 532 ms
48,684 KB
testcase_11 AC 601 ms
52,428 KB
testcase_12 AC 613 ms
54,228 KB
testcase_13 AC 492 ms
44,504 KB
testcase_14 AC 563 ms
49,952 KB
testcase_15 AC 627 ms
53,356 KB
testcase_16 AC 571 ms
50,272 KB
testcase_17 AC 569 ms
48,400 KB
testcase_18 AC 680 ms
58,980 KB
testcase_19 AC 824 ms
82,476 KB
testcase_20 AC 2 ms
3,480 KB
testcase_21 AC 1 ms
3,488 KB
testcase_22 AC 658 ms
56,952 KB
testcase_23 AC 1,466 ms
94,900 KB
testcase_24 AC 1,325 ms
88,876 KB
testcase_25 AC 1,462 ms
93,240 KB
testcase_26 AC 1 ms
3,376 KB
testcase_27 AC 1 ms
3,384 KB
testcase_28 AC 1,339 ms
88,808 KB
testcase_29 AC 1,440 ms
94,456 KB
testcase_30 AC 1,310 ms
86,124 KB
testcase_31 AC 1,218 ms
84,148 KB
testcase_32 AC 1,384 ms
87,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<map>
using namespace std;

int main(){
    long N,D;
    cin >> N >> D;
    unordered_map<int,long> sqsum; 

    for(int y=1;y<=N;y++){
        for(int z=1;z<=N;z++){
            sqsum[y*y+z*z]++;
        }
    }

    long ans = 0;
    for(long x=1;x<=N;x++){
        for(long w=1;w<=N;w++){
            long c = w*w - x*x + D;
            if(c < 2 || c > 2*N*N) continue;
            ans += sqsum[c];
        }
    }

    cout << ans << endl;
}
0