QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#112024#6328. Many Products8BQubeWA 1307ms4396kbC++203.8kb2023-06-09 15:11:092023-06-09 15:11:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-09 15:11:12]
  • 评测
  • 测评结果:WA
  • 用时:1307ms
  • 内存:4396kb
  • [2023-06-09 15:11:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())

const int MOD = 998244353;
const int L = 40;

void add(int &x, int val) {
    x += val;
    if (x >= MOD) x -= MOD;
}

int arr[200005];
int dp[2][L][L];
int C[5 * L][5 * L];

int H(int n, int m) {
    if (n + m - 1 < m) return 0;
    return C[n + m - 1][m];
}

int cal(const vector<int> &buk, int k) {
    if (buk.empty()) return k == 0;
    if (k == 0) return buk.empty();
    int sum = 0;
    for (int j : buk)
        sum += j;
    if (k > sum) return 0;
    int res = 0;
    for (int i = 0; i < k; ++i) {
        int cur = 1;
        for (int j : buk)
            cur = (ll)cur * H(k - i, j) % MOD;
        cur = (ll)cur * C[k][i] % MOD;
        if (i & 1) add(res, MOD - cur);
        else add(res, cur);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    ll m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    C[0][0] = 1;
    for (int i = 1; i < 5 * L; ++i) {   
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = C[i - 1][j];
            add(C[i][j], C[i - 1][j - 1]);
        }
    }
    vector<ll> p;
    {
        ll x = m;
        for (ll i = 2; i * i <= x; ++i)
            if (x % i == 0) {
                p.pb(i);
                while (x % i == 0) x /= i;
            }
        if (x > 1) p.pb(x);
    }
    vector<ll> fac;
    for (ll i = 1; i * i <= m; ++i)
        if (m % i == 0) {
            fac.pb(i);
            if (i * i != m) fac.pb(m / i);
        }
    dp[0][0][0] = 1;
    int prv = 0, nxt = 1;
    for (int i = 1; i <= n; ++i) {
        memset(dp[nxt], 0, sizeof(dp[nxt]));
        for (int j = 0; j < L; ++j)
            for (int k = 0; k < L; ++k)
                if (dp[prv][j][k]) {
                    add(dp[nxt][j + 1][k], dp[prv][j][k]); 
                    add(dp[nxt][j][k + 1], (ll)dp[prv][j][k] * arr[i] % MOD);
                    add(dp[nxt][j][k], (ll)dp[prv][j][k] * (arr[i] + 1) % MOD);
                }
        swap(prv, nxt);
    }
    int ans = 0;
    for (ll x : fac) {
        vector<int> buk, ibuk;
        for (ll j : p) {
            ll cur = x;
            if (cur % j == 0) {
                buk.pb(0);
                while (cur % j == 0) cur /= j, ++buk.back();
            }
            cur = m / x;
            if (cur % j == 0) {
                ibuk.pb(0);
                while (cur % j == 0) cur /= j, ++ibuk.back();
            }
        }
        vector<int> mth, imth;
        for (int j = 0; j < L; ++j) {
            mth.pb(cal(buk, j));
            imth.pb(cal(ibuk, j));
        }
        if (x == 1) {
            for (int j = 0; j < L; ++j)
                cerr << mth[j] << " ";
            cerr << endl;
            for (int j = 0; j < L; ++j)
                cerr << imth[j] << " ";
            cerr << endl;
        }
        int cur = 0;
        for (int j = 0; j < L; ++j)
            for (int k = 0; k < L; ++k) {
                add(cur, (ll)dp[prv][j][k] % MOD * mth[j] % MOD * imth[k] % MOD);
            }
        add(ans, (ll)cur * (x % MOD) % MOD);
        //cerr << x << ": " << cur << "\n";
    }
    /*vector<int> buk;
    for (ll j : p) {
        ll cur = m;
        if (cur % j == 0) {
            buk.pb(0);
            while (cur % j == 0) cur /= j, ++buk.back();
        }
    }

    int mul = 1;
    for (int i = 1; i <= n; ++i)
        mul = (ll)mul * arr[i] % MOD;

    for (int k = 1; k < L; ++k)
        add(ans, (ll)cal(buk, k) * mul % MOD);

    if (m > 1) add(ans, MOD - mul);*/

    cout << ans << "\n";

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 3564kb

input:

2 3
0 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

5 1
0 1 2 3 4

output:

120

result:

ok 1 number(s): "120"

Test #3:

score: 0
Accepted
time: 10ms
memory: 3528kb

input:

10 314159265358
0 1 2 3 4 5 6 7 8 9

output:

658270849

result:

ok 1 number(s): "658270849"

Test #4:

score: -100
Wrong Answer
time: 1307ms
memory: 4396kb

input:

200000 999999999989
823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...

output:

54531740

result:

wrong answer 1st numbers differ - expected: '777405593', found: '54531740'