QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#223275 | #7607. The Doubling Game 2 | ucup-team296# | WA | 1ms | 3696kb | C++14 | 3.8kb | 2023-10-21 23:23:07 | 2023-10-21 23:23:07 |
Judging History
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; k++) {
vector<mint> d(1 << (k + 1));
d[0] = 1;
if (x == 3) {
cout << "";
}
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;
}
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: 100
Accepted
time: 0ms
memory: 3696kb
input:
5 1 2 1 3 1 4 4 5
output:
21
result:
ok single line: '21'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3692kb
input:
128 11 32 116 81 65 4 117 47 5 81 104 30 61 8 82 59 95 20 92 29 29 127 97 39 123 33 59 128 115 33 83 67 74 16 77 33 64 73 124 123 8 127 61 51 101 122 35 90 119 116 112 27 81 93 109 123 54 1 119 100 116 16 65 47 67 27 22 105 76 87 36 39 27 96 72 31 91 123 21 105 118 12 110 48 121 72 14 115 24 16 106 ...
output:
49437626
result:
wrong answer 1st lines differ - expected: '508800953', found: '49437626'