QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291929 | #7607. The Doubling Game 2 | light_ink_dots | WA | 4ms | 25356kb | C++14 | 2.5kb | 2023-12-27 14:01:03 | 2023-12-27 14:01:04 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=6e5+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]+1;
while((n)<(1<<lim)) lim--;
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(((1<<(i+1))<s)) continue;
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;
}
(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;
}
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])%=mod;
}
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<<g[4][0]<<" "<<g[1][1]<<endl;
cout<<h[rt];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 25356kb
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: 23920kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 25020kb
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:
944185184
result:
wrong answer 1st lines differ - expected: '508800953', found: '944185184'