結果

問題 No.1318 ABCD quadruplets
コンテスト
ユーザー vjudge1
提出日時 2026-02-11 01:49:02
言語 JavaScript
(node v25.6.0)
結果
WA  
実行時間 -
コード長 1,489 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 262 ms
コンパイル使用メモリ 8,352 KB
実行使用メモリ 59,528 KB
最終ジャッジ日時 2026-02-11 01:49:09
合計ジャッジ時間 7,149 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
    inputString += inputStdin;
})

process.stdin.on('end', (_) => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
})

function readLine() {
    return inputString[currentLine++];
}

function countTuples(N, M) {
    const f = new Array(N + 1).fill(0);

    // Map: "sum,sq" ? count
    const map = new Map();

    for (let a = 0; a <= M; a++) {
        for (let b = 0; b <= M; b++) {
            const sum = a + b;
            const sq = a * a + b * b;
            const key = sum + "," + sq;
            map.set(key, (map.get(key) || 0) + 1);
        }
    }

    const entries = Array.from(map.entries());

    for (let i = 0; i < entries.length; i++) {
        const [key1, cnt1] = entries[i];
        const [s1, q1] = key1.split(",").map(Number);

        for (let j = 0; j < entries.length; j++) {
            const [key2, cnt2] = entries[j];
            const [s2, q2] = key2.split(",").map(Number);

            const S = s1 + s2;
            const Q = q1 + q2;
            const value = (S * S + Q) >> 1;

            if (value <= N) {
                f[value] += cnt1 * cnt2;
            }
        }
    }

    return f;
}



function main() {
    const [N, M] = readLine().split(' ').map(Number);
    const f = countTuples(N, M);
    console.log(f.join(' '));
}
0