結果

問題 No.125 悪の花弁
ユーザー t98slidert98slider
提出日時 2022-06-14 07:07:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 3,119 ms
コンパイル使用メモリ 143,504 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2023-07-25 04:27:38
合計ジャッジ時間 3,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,992 KB
testcase_01 AC 14 ms
6,244 KB
testcase_02 AC 16 ms
7,524 KB
testcase_03 AC 17 ms
7,552 KB
testcase_04 AC 8 ms
6,936 KB
testcase_05 AC 8 ms
6,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/all>
using namespace std;
using mint = atcoder::modint1000000007;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, Csum = 0, gcdv = 0;
    cin >> K;
    vector<int> C(K), y;
    for(auto &&v:C){
        cin >> v;
        gcdv = __gcd(gcdv, v);
        Csum += v;
    }
    vector<mint> fact(Csum + 1);
    fact[0] = 1;
    for(int i = 1; i <= Csum; i++)fact[i] = i * fact[i - 1];
    for(int i = 1; i * i <= gcdv; i++){
        if(gcdv % i == 0){
            y.push_back(i);
            if(gcdv / i != i)y.push_back(gcdv / i);
        }
    }
    sort(y.rbegin(), y.rend());
    vector<mint> calc(y.size());
    mint ans;
    for(int i = 0; i < y.size(); i++){
        int d = y[i];
        calc[i] = fact[Csum / d - 1];
        mint div = fact[C[0] / d - 1];
        for(int j = 1; j < K; j++)div *= fact[C[j] / d];
        calc[i] /= div;
        for(int j = 0; j < i; j++){
            if(y[j] % y[i] == 0)calc[i] -= calc[j];
        }
        ans += calc[i] / (C[0] / d);
    }
    cout << ans.val() << '\n';
}
0