結果

問題 No.473 和と積の和
ユーザー PachicobuePachicobue
提出日時 2018-11-21 17:39:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 3,000 ms
コード長 1,393 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 220,456 KB
実行使用メモリ 17,488 KB
最終ジャッジ日時 2023-08-26 02:39:21
合計ジャッジ時間 5,650 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 60 ms
9,488 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 217 ms
17,488 KB
testcase_26 AC 46 ms
8,396 KB
testcase_27 AC 70 ms
9,400 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 140 ms
10,176 KB
testcase_35 AC 120 ms
10,160 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 108 ms
10,160 KB
testcase_39 AC 55 ms
6,272 KB
testcase_40 AC 61 ms
6,276 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 44 ms
16,120 KB
testcase_43 AC 62 ms
16,116 KB
testcase_44 AC 79 ms
15,984 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
template <typename T, typename A>
std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) { os << p << ","; }
    return (os << "]\n");
}
int main()
{
    int N, X;
    std::cin >> N >> X, X++;
    if (N >= 30) { return std::cout << 0 << std::endl, 0; }
    std::vector<int> d;
    for (int i = 1; i * i <= X; i++) {
        if (X % i != 0) { continue; }
        d.push_back(i);
        if (i * i != X) { d.push_back(X / i); }
    }
    const int S = d.size();
    std::sort(d.begin(), d.end());
    std::map<int, int> mp;
    for (int i = 0; i < S; i++) { mp[d[i]] = i; }
    std::vector<std::vector<int>> dp(S, std::vector<int>(S, 0));  // 積=d[i], 最後に使った約数<=d[j]
    std::fill(dp[0].begin(), dp[0].end(), 1);
    for (int i = 0; i < N; i++) {
        std::vector<std::vector<int>> tmp(S, std::vector<int>(S, 0));
        for (int j = S - 1; j >= 0; j--) {
            for (int k = j; k >= 1; k--) {
                if (d[j] % d[k] == 0) { tmp[j][k] = dp[mp[d[j] / d[k]]][k]; }
            }
        }
        dp = tmp;
        for (int i = 0; i < S; i++) {
            for (int j = 1; j < S; j++) { dp[i][j] += dp[i][j - 1]; }
        }
    }
    std::cout << dp[S - 1][S - 1] << std::endl;
    return 0;
}
0