結果

問題 No.368 LCM of K-products
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-06 02:04:57
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,113 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 67,288 KB
実行使用メモリ 793,204 KB
最終ジャッジ日時 2024-04-20 22:07:22
合計ジャッジ時間 7,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>
using namespace std;

typedef long long ll;

const ll kMOD = 1000 * 1000 * 1000 + 7;
const int kMAX_N = 1010;
const int kMAX_K = 1010;

int N, K;
set<ll> dp[kMAX_N][kMAX_K];
ll a[kMAX_N];

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    return a * b / GCD(a, b);
}

void Solve() {
    dp[0][0].insert(1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= K; j++) {
            if (dp[i][j].empty()) continue;
            for (set<ll>::iterator it = dp[i][j].begin(); it != dp[i][j].end(); it++) {
                dp[i + 1][j].insert(*it);
                if (j + 1 > K) continue;
                dp[i + 1][j + 1].insert((*it * a[i]) % kMOD);
            }
        }
    }
    ll answer = 1;
    for (set<ll>::iterator it = dp[N][K].begin(); it != dp[N][K].end(); it++) {
        answer = LCM(answer, *it);
        answer %= kMOD;
    }
    cout << answer << endl;
}

int main() {
    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    Solve();

    return 0;
}
0