QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282719 | #7607. The Doubling Game 2 | light_ink_dots | WA | 0ms | 21032kb | C++14 | 2.8kb | 2023-12-12 20:37:49 | 2023-12-12 20:37:50 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=3e5+100;
const int mod=1e9+7;
#define int long long
int n;
vector<int>v[N];
int dp[N][20],g[N][20],h[N];
int f[N];
int mex(const vector<int>&a){
static int vis[30];
memset(vis,0,sizeof(vis));
for(int x:a)
for(int i=0;i<=x;i++) vis[i]++;
for(int k=0;k<=20;k++){
for(int j=0;j<=k;j++){
if(vis[j]-(k+1)+j<0)return k;
}
}
}
void pfs(int x,int fa){
vector<int>s;
for(auto y:v[x]){
if(y==fa) continue;
pfs(y,x);
s.push_back(f[y]);
}
f[x]=mex(s);
// cerr<<"? "<<x<<" "<<f[x]<<endl;
}
int d[N][20],tg[N][20];
void dfs(int x,int fa){
vector<int>out;
for(int y:v[x]) if(y!=fa) out.push_back(y);
sort(out.begin(),out.end(),[&](int u,int v){
return f[u]<f[v];
});
// h[x]=1;
for(auto y:out)dfs(y,x);
int lim=f[x];
for(int s=0;s<(1<<(lim+1));s++){
memset(d[s],0,sizeof(d[s]));
}
d[0][0]=1;
for(auto y:out){
for(int s=0;s<(1<<min(lim,f[y]+1));s++){
memset(tg[s],0,sizeof(tg[s]));
}
for(int s=0;s<(1<<min(lim,f[y]+1));s++) {
for(int j=0;j<=lim+1;j++){
tg[s][j]=d[s][j]*h[y]%mod;
}
}
for(int s=0;s<(1<<min(lim,f[y]+1));s++){
for(int i=0;i<=min(f[y],lim);i++){
if((s>>i)&1) continue;
for(int j=0;j<=lim+1;j++){
(tg[s+(1<<i)][j]+=d[s][j]*dp[y][i])%=mod;
}
// for(int j=0;j<=lim+1;j++){
// if(x==1&&s==0) cerr<<tg[0][1]<<endl;
(tg[s][i+1]+=d[s][0]*g[y][i])%=mod;
// }
}
}
for(int s=0;s<(1<<min(lim,f[y]+1));s++){
memcpy(d[s],tg[s],sizeof(d[s]));
}
}
for(int i=0;i<=lim;i++){
dp[x][i]=d[(1<<i)-1][0];
(h[x]+=dp[x][i])%=mod;
}
// if(x==1) cerr<<h[x]<<" "<<d[1][2]<<" "<<d[0][1]<<" "<<g[2][0]<<endl;
// cerr<<"??? "<<x<<" "<<g[2][0]<<" "<<d[0][1]<<endl;
for(int i=0;i<=lim+1;i++){
//j 空
for(int j=0;j<i;j++){
g[x][j]+=d[(1<<i)-(1<<j)-1][i+1];
}
for(int j=0;j<i;j++){
(g[x][j]+=d[(1<<i)-(1<<j)-1][0])%=mod;
}
(h[x]+=d[(1<<i)-1][i+1])%=mod;
}
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
v[x].push_back(y),v[y].push_back(x);
}
int rt=1;
pfs(rt,0);
dfs(rt,0);
// cerr<<"????? "<<f[1]<<" "<<h[2]<<" "<<g[2][1]<<" "<<g[2][0]<<endl;
cout<<h[rt];
}
/*
3
1 2
2 3
5
1 2
1 3
1 4
4 5
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 19708kb
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: 19404kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 21032kb
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:
29025983
result:
wrong answer 1st lines differ - expected: '508800953', found: '29025983'