QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#223312#7607. The Doubling Game 2ucup-team296#WA 0ms3592kbC++143.8kb2023-10-21 23:56:022023-10-21 23:56:02

Judging History

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

  • [2023-10-21 23:56:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2023-10-21 23:56:02]
  • 提交

answer

#include <bits/stdc++.h>

#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

int mod = 1000000007;

struct mint {
    int value = 0;

    constexpr mint() : value() {}

    mint(const long &x) {
        value = normalize(x);
    }

    static long normalize(const long &x) {
        long v = x % mod;
        if (v < 0) v += mod;
        return v;
    }

    bool operator==(const mint &x) { return value == x.value; };

    mint operator+(const mint &x) { return value + x.value; };

    mint operator-(const mint &x) { return value - x.value; };

    mint operator*(const mint &x) { return (long) value * x.value; };

    void operator+=(const mint &x) { value = normalize(value + x.value); };

    void operator-=(const mint &x) { value = normalize(value - x.value); };
};


vector<vector<int>> g;

void dfs1(int x, int p) {
    vector<int> gg;
    for (int y : g[x]) {
        if (y == p) continue;
        dfs1(y, x);
        gg.push_back(y);
    }
    g[x] = gg;
}

vector<vector<mint>> dp1;
vector<vector<vector<mint>>> dp2;
vector<mint> dp3;

void go(int x) {
    vector<pair<int, int>> a;
    for (int y : g[x]) {
        go(y);
        a.push_back({dp1[y].size() - 1, y});
    }
    sort(a.begin(), a.end());
    int maxk = 0;
    for (auto p : a) {
        if (p.first >= maxk) maxk++;
    }
    dp1[x].resize(maxk + 1);
    dp2[x].resize(maxk + 2);
    for (int k = 0; k <= maxk + 1; k++) {
        vector<mint> d(1 << k);
        d[0] = 1;
        for (int y : g[x]) {
            vector<mint> dd(1 << k);
            for (int m = 0; m < (1 << k); m++) {
                for (int i = 0; i < k && i < (int)dp1[y].size(); i++) {
                    if (m & (1 << i)) continue;
                    int mm = m | (1 << i);
                    dd[mm] += d[m] * dp1[y][i];
                }
                dd[m] += d[m] * dp3[y];
            }
            d = dd;
        }
        if (k <= maxk)
            dp1[x][k] = d[(1 << k) - 1];
        dp2[x][k].resize(k);
        for (int i = 0; i < k; i++) {
            dp2[x][k][i] += d[(1 << k) - 1 - (1 << i)];
        }
        dp3[x] += dp1[x][k];
    }
    for (int k = 0; k <= maxk + 1; k++) {
        vector<mint> d(1 << (k + 1));
        d[0] = 1;
        for (int y : g[x]) {
            vector<mint> dd(1 << (k + 1));
            for (int m = 0; m < (1 << (k + 1)); m++) {
                for (int i = 0; i < k && i < (int)dp1[y].size(); i++) {
                    if (m & (1 << i)) continue;
                    int mm = m | (1 << i);
                    dd[mm] += d[m] * dp1[y][i];
                }
                if ((m & (1 << k)) == 0) {
                    for (int i = k + 1; i < (int) dp2[y].size(); i++) {
                        int mm = m | (1 << k);
                        dd[mm] += d[m] * dp2[y][i][k]; 
                    }
                }
                dd[m] += d[m] * dp3[y];
            }
            d = dd;
        }
        for (int i = 0; i < k; i++) {
            dp2[x][k][i] += d[(1 << (k + 1)) - 1 - (1 << i)];
        }
        dp3[x] += d[(1 << (k + 1)) - 1];
    }
    cout << (x + 1) << ":\n";
    for (auto t : dp1[x]) {
        cout << t.value << " ";
    }
    cout << "\n";
    for (auto q : dp2[x]) {
        cout << ">";
        for (auto t : q) {
            cout << t.value << " ";
        }
        cout << "\n";
    }
    cout << dp3[x].value << "\n";
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs1(0, -1);

    dp1.resize(n);
    dp2.resize(n);
    dp3.resize(n);
    go(0);
    cout << dp3[0].value << "\n";

    return 0;
}


詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

input:

5
1 2
1 3
1 4
4 5

output:

2:
1 
>
>1 
1
3:
1 
>
>1 
1
5:
1 
>
>1 
1
4:
1 1 
>
>1 
>0 1 
3
1:
3 7 2 
>
>4 
>1 7 
>0 0 2 
21
21

result:

wrong answer 1st lines differ - expected: '21', found: '2:'