結果

問題 No.1318 ABCD quadruplets
コンテスト
ユーザー vjudge1
提出日時 2026-02-11 01:52:45
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,564 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,072 ms
コンパイル使用メモリ 134,400 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-11 01:52:51
合計ジャッジ時間 6,384 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>

using namespace std;

int get_permutations(int a, int b, int c, int d)
{
    if (a == b && b == c && c == d)
        return 1;
    if (a == b && b == c || b == c && c == d)
        return 4;
    if (a == b && c == d)
        return 6;
    if (a == b || b == c || c == d)
        return 12;
    return 24;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    if (!(cin >> N >> M))
        return 0;

    vector<int> counts(N + 1, 0);

    for (int a = 0; a <= M; ++a)
    {
        long long a2 = (long long)a * a;
        for (int b = a; b <= M; ++b)
        {
            long long ab_sum = a2 + (long long)b * b + (long long)a * b;
            if (ab_sum > N)
                break;

            for (int c = b; c <= M; ++c)
            {
                long long abc_sum = ab_sum + (long long)c * c + (long long)a * c + (long long)b * c;
                if (abc_sum > N)
                    break;

                for (int d = c; d <= M; ++d)
                {
                    long long total = abc_sum + (long long)d * d + (long long)a * d + (long long)b * d + (long long)c * d;

                    if (total <= N)
                    {
                        counts[total] += get_permutations(a, b, c, d);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (int n = 0; n <= N; ++n)
    {
        cout << counts[n] << "\n";
    }

    return 0;
}
0