提交记录 11472


用户 题目 状态 得分 用时 内存 语言 代码长度
linxi noi18f. 【NOI2018】多边形 Wrong Answer 0 697.259 ms 24588 KB C++11 3.25 KB
提交时间 评测时间
2020-01-17 14:46:56 2020-08-01 02:43:55
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
const ll mod = 998244353LL;
ll num[55], n, k, ans;
ll C[55][55], fac[55], invFac[55], inv[55];
ll pw(ll x, ll y, ll z) {
    ll ret = 1;
    while(y > 0) {
        if((y & 1) == 1) ret = ret*x%mod;
        x = x*x%mod;
        y >>= 1;
    }
    return ret;
}
void init() {
    C[1][0] = C[1][1] = 1;
    for(int i = 2; i <= 50; ++i) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; ++j) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            C[i][j] %= mod;
        }
    }
    fac[0] = 1;
    for(int i = 1; i <= 50; ++i) {
        fac[i] = fac[i - 1]*i%mod;
        // printf("%d %lld\n", i, fac[i]);
    }
    invFac[50] = pw(fac[50], mod - 2, mod);
    for(int i = 49; i >= 0; --i) {
        invFac[i] = invFac[i + 1]*(i + 1)%mod;
        // printf("%d %lld\n", i, invFac[i]);
    }
    // for(int i = 1; i <= 5; ++i) {
    //     for(int j = 0; j <= i; ++j) {
    //         printf("%lld ", C[i][j]);
    //     }
    //     puts("");
    // }
}
vector<ll> L[55], Num[55];
void calc(ll tot) {
    // if(num[tot - 1] > 3) return ;
    // puts("-----------------");
    // puts("In calc: ");
    // for(int i = 0; i < tot; ++i) {
    //     printf("%lld ", num[i]);
    // }
    // puts("");
    // puts("-----------------");
    ll d = 0;
    for(int i = 0; i < tot; ++i) {
        d = __gcd(d, num[i]);
    }
    ll lcm = num[0];
    for(int i = 1; i < tot; ++i) {
        lcm = num[i]/__gcd(lcm, num[i])*lcm;
    }
    // printf("%lld %lld\n", d, lcm);
    ll now = C[n][num[0]]*fac[num[0] - 1]%mod, lst = num[0], cnt = 1, rm = n - num[0];
    for(int i = 1; i < tot; ++i) {
        now *= C[rm][num[i]]*fac[num[i] - 1]%mod;
        now %= mod;
        rm -= num[i];
        if(num[i] == num[i - 1]) {
            ++cnt;
        } else {
            now = now*invFac[cnt]%mod;
            lst = num[i];
            cnt = 1;
        }
    }
    now = now*invFac[cnt]%mod;
    L[n].push_back(lcm);
    Num[n].push_back(now);
    // printf("now: %lld\n", now);
}
void dfs(ll pos, ll mi, ll rm) {
    // puts("++++++++++++++++++++++");
    // puts("In dfs: ");
    // printf("pos: %lld mi: %lld rm: %lld gcd: %lld lcm: %lld\n", pos, mi, rm, d, lcm);
    // for(int i = 0; i < pos; ++i) {
    //     printf("%lld ", num[i]);
    // }
    // puts("");
    // puts("++++++++++++++++++++++");
    if(rm == 0) {
        // calc(pos, d, lcm);
        calc(pos);
        return ;
    }
    for(ll i = mi; i <= rm; ++i) { 
        num[pos] = i;
        // ll nd = __gcd(d, i);
        // ll nlcm = i/__gcd(lcm, i)*lcm;
        // if(k%nlcm == 0) dfs(pos + 1, i, rm - i, nd, nlcm);
        dfs(pos + 1, i, rm - i);
    }
}
void GetAnswer() {
    for(ll i = 1; i <= 50; ++i) {
        n = i;
        // if(n == 50)
        dfs(0, 1, n);
        // printf("%lld %d\n", n, L[n].size());
    }
}
int main() {
    init();
    GetAnswer();
    // int T; scanf("%d", &T);
    // for(int cs = 1; cs <= T; ++cs) {
    //     scanf("%lld%lld", &n, &k);
    //     ans = 0;
    //     int sz = L[n].size();
    //     for(int i = 0; i < sz; ++i) {
    //         if(k%L[n][i] == 0) {
    //             ans = (ans + Num[n][i])%mod;
    //         }
    //     }
    //     printf("%lld\n", ans);
    // }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1697.137 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #2697.259 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #3697.246 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #4697.129 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #5697.101 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #6697.103 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #7697.107 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #8697.086 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #9697.134 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #10697.088 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #11697.149 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #12697.129 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #13697.176 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #14697.083 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #15697.196 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #16697.105 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #17697.082 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #18697.099 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #19697.172 ms24 MB + 12 KBWrong AnswerScore: 0

Testcase #20697.125 ms24 MB + 12 KBWrong AnswerScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-27 17:59:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠