結果

問題 No.800 四平方定理
ユーザー shi-moshi-mo
提出日時 2020-09-29 23:27:50
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 136,944 KB
実行使用メモリ 68,304 KB
最終ジャッジ日時 2023-09-04 10:09:45
合計ジャッジ時間 5,089 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 3 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,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 49 ms
34,740 KB
testcase_11 AC 49 ms
38,092 KB
testcase_12 AC 55 ms
39,000 KB
testcase_13 AC 41 ms
35,960 KB
testcase_14 AC 48 ms
39,812 KB
testcase_15 AC 53 ms
39,324 KB
testcase_16 AC 48 ms
38,600 KB
testcase_17 AC 48 ms
39,120 KB
testcase_18 AC 58 ms
39,120 KB
testcase_19 AC 62 ms
38,556 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 59 ms
39,852 KB
testcase_23 AC 110 ms
67,456 KB
testcase_24 AC 101 ms
66,172 KB
testcase_25 AC 111 ms
67,260 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 100 ms
65,688 KB
testcase_29 AC 107 ms
68,304 KB
testcase_30 AC 103 ms
66,440 KB
testcase_31 AC 83 ms
61,572 KB
testcase_32 AC 102 ms
66,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.conv;
import std.array;

void main() {
    uint n, d;
    readf("%s %s\n", &n, &d);

    immutable uint m = 2*n*n;
    uint[] cxy = new uint[](m+1);
    uint[] cwz = new uint[](m+1);

    foreach (i; 1..(n+1)) {
        uint i2 = i*i;
        foreach (j; 1..(n+1)) {
            uint j2 = j*j;
            cxy[i2 + j2]++;

            uint wz = i2 - j2 + d;
            if (0 < wz && wz <= m) {
                cwz[wz]++;
            }
        }
    }

    uint sum = 0;
    foreach (i; 2..(m+1)) {
        sum += cxy[i] * cwz[i];
    }
    writef("%d\n", sum);
}
0