QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430549#8747. 朔望hhoppitreeML 0ms0kbC++172.9kb2024-06-03 22:34:062024-06-03 22:34:07

Judging History

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

  • [2024-06-03 22:34:07]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-06-03 22:34:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 20, P = 1e9 + 7;

int ksm(int x, int y = P - 2) {
    int res = 1;
    while (y) {
        if (y & 1) {
            res = 1ll * res * x % P;
        }
        x = 1ll * x * x % P; y >>= 1;
    }
    return res;
}

int T[N], w[N + 1], C[N + 1][N + 1];
unordered_map<int, int> M[N][N], dp[1 << N];
vector< pair<int, int> > D[N];

vector< pair<int, int> > divide(int x) {
    vector< pair<int, int> > res;
    for (int i = 2; i * i <= x; ++i) {
        if (!(x % i)) {
            int C = 0;
            while (!(x % i)) {
                x /= i, ++C;
            }
            res.push_back({i, C});
        }
    }
    if (x != 1) res.push_back({x, 1});
    return res;
}

signed main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &T[i]);
    }
    for (int i = 2; i <= n; ++i) {
        scanf("%d", &w[i]);
    }
    for (int i = C[0][0] = 1; i <= n; ++i) {
        C[i][0] = 1;
        for (int j = C[i][0] = 1; j <= i; ++j) {
            ((C[i][j] = C[i - 1][j - 1] + C[i - 1][j]) >= P) && (C[i][j] -= P);
        }
    }
    for (int i = 3; i <= n; ++i) {
        for (int j = 2; j < i; ++j) {
            w[i] = (w[i] - 1ll * w[j] * C[i][j] % P + P) % P;
        }
    }
    for (int i = 0; i < n; ++i) {
        D[i] = divide(T[i]);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                if (k != i && k != j) {
                    for (auto [x, y] : D[k]) {
                        M[i][j][x] += y;
                    }
                }
            }
            vector< pair<int, int> > t = divide(T[j] - T[i]);
            for (auto [x, y] : t) {
                M[i][j][x] += y;
            }
        }
    }
    for (int i = 1; i < 1 << n; ++i) {
        if (__builtin_popcount(i) == 1) continue;
        int j = -1, k;
        for (int z = 0; z < n; ++z) {
            if ((i >> z) & 1) {
                if (!~j) j = z;
                else {k = z; break;}
            }
        }
        if (__builtin_popcount(i) == 2) {
            dp[i] = M[j][k];
            continue;
        }
        dp[i] = dp[i ^ (1 << j)];
        vector<int> del;
        for (auto &[x, y] : dp[i]) {
            if (!M[j][k].count(x)) del.push_back(x);
            else y = min(y, M[j][k][x]);
        }
        for (auto x : del) {
            dp[i].erase(x);
        }
    }
    int res = 0;
    for (int i = 1; i < 1 << n; ++i) {
        if (!w[__builtin_popcount(i)]) continue;
        int val = 2;
        for (auto [x, y] : dp[i]) {
            val = 1ll * val * ksm(x, y) % P;
        }
        res = (res + 1ll * val * w[__builtin_popcount(i)]) % P;
    }
    for (int i = 0; i < n; ++i) {
        res = 1ll * res * ksm(T[i]) % P;
    }
    printf("%d\n", res);
    return 0;
}

詳細信息

Test #1:

score: 0
Memory Limit Exceeded

input:

20
73415948 190825288 205086969 242726140 280691039 291234110 341933576 379938879 399631744 420807939 421811250 486105558 605031352 645495854 714594262 775221445 793534057 818237037 926135349 940293639
108200337 125078426 163639475 261733041 280562529 287327830 310288774 415301468 419144734 46329977...

output:

153969420

result: