QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642129#4811. Be CarefulhhoppitreeCompile Error//C++174.0kb2024-10-15 10:40:282024-10-15 10:40:28

Judging History

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

  • [2024-10-15 10:40:28]
  • 评测
  • [2024-10-15 10:40:28]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 205, P = 998244353;

struct MOD {
    int operator ()(long long x) {
        return x - (((__int128)x * 18479187002) >> 64) * P;
    }
} mod;

vector<int> G[N];
int n, dp[N][N], sdp[N][N], f[2][1 << 18], g[1 << 18][N], h[1 << 18], C[N][N];

void dfs(int x, int fa = -1) {
    int deg = 0, cnt = 0;
    for (auto v : G[x]) {
        if (v != fa) {
            dfs(v, x);
            for (int i = n; i >= 0; --i) {
                sdp[v][i] = mod(sdp[v][i + 1] + dp[v][i]);
            }
            cnt += (G[v].size() == 1), ++deg;
        }
    }
    if (!deg) {
        fill(dp[x], dp[x] + n + 1, 1);
        return;
    }
    vector< pair<int, int> > o;
    for (auto v : G[x]) {
        if (v != fa && G[v].size() != 1) {
            int L = n;
            while (!dp[v][L]) --L;
            o.push_back({L, v});
        }
    }
    sort(o.begin(), o.end());
    int mn = o.size() + 1, ps = -1;
    for (int i = 0; i < (int)o.size(); ++i) {
        if (o[i].first + ((int)o.size() - i) < mn) {
            mn = o[i].first + ((int)o.size() - i), ps = i;
        }
    }
    int tz = (!~ps ? 0 : o[ps].first + 1);
    for (int i = 0; i < 1 << tz; ++i) f[0][i] = !i;
    for (int i = 0; i <= ps; ++i) {
        for (int j = 0; j < 1 << tz; ++j) f[1][j] = f[0][j], f[0][j] = 0;
        for (int j = (1 << (o[i].first + 1)) - 1; ~j; --j) {
            for (int k = 0; k <= o[i].first; ++k) {
                f[0][j | (1 << k)] = mod(f[0][j | (1 << k)] + 1ll * f[1][j] * dp[o[i].second][k]);
            }
        }
    }
    for (int i = 0; i < 1 << tz; ++i) if (f[0][i]) {
        int z = o.size() - 1 - ps;
        for (int j = 0; j < (1 << z); ++j) {
            for (int k = 0; k <= cnt; ++k) g[j][k] = 0;
        }
        g[(1 << z) - 1][cnt] = f[0][i];
        for (int j = 0; ; ++j) {
            int ok = 0;
            for (int k = 0; k < (1 << z); ++k) {
                for (int l = 0; l <= cnt; ++l) {
                    if (g[k][l] %= P) ok = 1;
                }
            }
            if (!ok) break;
            for (int l = 0; l <= cnt; ++l) {
                vector< pair<int*, int> > del;
                for (int k = 0; k < (1 << z); ++k) {
                    h[k] = g[k][l];
                    del.push_back({&g[k][l], g[k][l]});
                    if (g[k][l] && (j >= 30 || !((i >> j) & 1))) {
                        del.push_back({&g[k][l], g[k][l]});
                        int mul = g[k][l];
                        for (int t = 1; t <= l; ++t) mul = mod(1ll * mul * (n - j));
                        for (int p = 0; p < z; ++p) {
                            if ((k >> p) & 1) {
                                mul = mod(1ll * mul * sdp[o[ps + 1 + p].second][j + 1]);
                            }
                        }
                        dp[x][j] = mod(dp[x][j] + mul);
                    }
                }
                for (int k = 0; k < z; ++k) {
                    for (int p = 0; p < (1 << z); ++p) {
                        if (!((p >> k) & 1)) {
                            h[p] = mod(h[p] + 1ll * h[p | (1 << k)] * dp[o[ps + 1 + k]][j]);
                        }
                    }
                }
                for (int k = 0; k < (1 << z); ++k) {
                    for (int L = 0; L <= l; ++L) {
                        g[k][L] = mod(g[k][L] + 1ll * h[k] * C[l][L]);
                    }
                }
                for (auto [x, y] : del) *x = mod(*x - y);
            }
        }
    }
}

signed main() {
    scanf("%d", &n);
    for (int i = C[0][0] = 1; i <= n; ++i) {
        for (int j = C[i][0] = 1; j <= i; ++j) {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;
        }
    }
    for (int i = 1, x, y; i < n; ++i) {
        scanf("%d%d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1);
    for (int i = 0; i <= n; ++i) printf("%d\n", (dp[1][i] % P + P) % P);
    return 0;
}

Details

answer.code: In function ‘void dfs(int, int)’:
answer.code:90:73: error: no match for ‘operator[]’ (operand types are ‘int [205][205]’ and ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, int>’})
   90 |                             h[p] = mod(h[p] + 1ll * h[p | (1 << k)] * dp[o[ps + 1 + k]][j]);
      |                                                                         ^
answer.code: In function ‘int main()’:
answer.code:106:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  106 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
answer.code:113:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  113 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~