結果

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

ソースコード

diff #
raw source code

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let input = '';
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', () => {
    main(input.trim().split(/\s+/).map(Number));
});

function main([N, M]) {
    let freq = new Map();

    // Step 1: count all a,b contributions
    for (let a = 0; a <= M; a++) {
        for (let b = 0; b <= M; b++) {
            let sum = a*a + a*b + b*b;
            freq.set(sum, (freq.get(sum) || 0) + 1);
        }
    }

    // Step 2: for each c,d compute sums and combine
    let result = Array(N+1).fill(0);
    for (let c = 0; c <= M; c++) {
        for (let d = 0; d <= M; d++) {
            let cdSum = c*c + c*d + d*d;
            for (let [abSum, count] of freq.entries()) {
                let total = abSum + cdSum;
                if (total <= N) {
                    result[total] += count;
                }
            }
        }
    }

    console.log(result.join('\n'));
}
0