QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404773 | #7607. The Doubling Game 2 | ucup-team3396# | WA | 4ms | 16420kb | C++14 | 2.4kb | 2024-05-04 17:52:35 | 2024-05-04 17:52:50 |
Judging History
answer
#pragma GCC optimize(2,3,"Ofast","inline","unroll-loops")
// #pragma GCC target("avx")
#include <bits/stdc++.h>
#define double long double
#define lowbit(i) (i&(-i))
#define mid ((l+r)>>1)
#define add(i,j) (((i+j)>=mod)?i+j-mod:i+j)
using namespace std;
const int mod=1e9+7;
int siz[300005];
vector<int> vc[300005];
int cnt[300005];
int dp[300005][35][3];
int f[1200005][2],g[1200005][2];
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void dfs(int now,int fa){
for(auto v:vc[now]){
if(v==fa) continue;
dfs(v,now);
}
for(auto v:vc[now]) if(v!=fa) cnt[siz[v]]++;
for(int i=20;i>=0;--i) cnt[i]+=cnt[i+1];
for(int i=20;i>=0;--i){
bool ok=1;
for(int j=0;j<i;++j){
if(cnt[j]<i-j) ok=0;
}
if(ok){
siz[now]=i;
break;
}
}
for(int i=0;i<=20;++i) cnt[i]=0;
for(int i=0;i<(1<<(siz[now]+2));++i) f[i][0]=f[i][1]=0;
f[0][0]=1;
for(auto v:vc[now]){
if(v==fa) continue;
for(int i=0;i<(1<<(siz[now]+2));++i) g[i][0]=g[i][1]=0;
int tot=0;
for(int j=0;j<=siz[v];++j) (tot+=dp[v][j][0]+dp[v][j][2])%=mod;
for(int j=0;j<=min(siz[v],siz[now]);++j){
for(int i=0;i<(1<<(siz[now]+2));++i){
if(!((i>>j)&1)){
g[i|(1<<j)][0]=add(g[i|(1<<j)][0],1ll*f[i][0]*dp[v][j][0]%mod);
if((1<<j)<i) g[i|(1<<j)][1]=add(g[i|(1<<j)][1],1ll*f[i][1]*dp[v][j][0]%mod);
if((1<<j)>i) g[i|(1<<j)][1]=add(g[i|(1<<j)][1],1ll*f[i][0]*dp[v][j][1]%mod);
}
}
}
for(int i=0;i<(1<<(siz[now]+2));++i) f[i][0]=(1ll*f[i][0]*tot+g[i][0])%mod,f[i][1]=(1ll*f[i][1]*tot+g[i][1])%mod;
}
for(int i=0;i<=siz[now];++i){
dp[now][i][0]=f[(1<<i)-1][0];
dp[now][i][2]=f[(1<<i)-1+(1<<i)][1];
}
for(int i=0;i<=siz[now]+1;++i){
for(int j=0;j<i;++j){
dp[now][j][1]=add(dp[now][j][1],add(f[(1<<i)-1-(1<<j)][0],f[(1<<i)-1-(1<<j)+(1<<i)][1]));
// if(now==4&&i==1&&j==0) cout<<"OK"<<f[(1<<i)-1-(1<<j)][0]<<" "<<f[(1<<i)-1-(1<<j)+(1<<i)][1]<<" "<<dp[now][j][1]<<" ";
}
}
// cout<<now<<" "<<siz[now]<<"\n";
// for(int i=0;i<=siz[now]+1;i++) cout<<dp[now][i][0]<<" "<<dp[now][i][1]<<" "<<dp[now][i][2]<<"\n";
}
signed main(){
int n; n=read();
for(int i=1;i<n;i++){
int u,v; u=read(),v=read();
vc[u].emplace_back(v);
vc[v].emplace_back(u);
}
dfs(1,0);
int ans=0;
for(int i=0;i<=siz[1];++i) (ans+=dp[1][i][0]+dp[1][i][2]);
cout<<ans%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 16124kb
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: 16316kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 16420kb
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:
-786166322
result:
wrong answer 1st lines differ - expected: '508800953', found: '-786166322'