QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227419 | #7607. The Doubling Game 2 | ucup-team1004 | WA | 3ms | 15736kb | C++14 | 2.5kb | 2023-10-27 15:14:39 | 2023-10-27 15:14:40 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=3e5+5,M=N*4+5,K=(1<<25)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,Si[N];ll dp[N][20][2],p[N];
vector<int> S[N];
void dfs(int x,int La){
Si[x]=1;for(int i:S[x]) if(i^La) dfs(i,x),Si[x]+=Si[i];
vector<int> son;for(int i:S[x]) if(i^La) son.eb(i);
sort(son.begin(),son.end(),[](int x,int y){return Si[x]<Si[y];});
int k=0;
vector<int> f(2),g(2);f[0]=1;
for(int i:son){
if(i!=son.back()) k=__lg(Si[i]);
else k++;
f.resize(1<<k+1);g.resize(1<<k+1);
g=f;for(int j=0;j<(1<<k+1);j++) f[j]=f[j]*p[i]%mod;
for(int j=0;j<k+1;j++) if(dp[i][j][0]) {
for(int h=0;h<(1<<k+1);h++) if(!(h>>j&1)) f[h^(1<<j)]=(f[h^(1<<j)]+g[h]*dp[i][j][0])%mod;
}
}
for(int i=0;i<=k+1;i++){
dp[x][i][0]=f[(1<<i)-1];
p[x]+=dp[x][i][0];
for(int j=0;j<i;j++) dp[x][j][1]=(dp[x][j][1]+f[(1<<i)-1-(1<<j)])%mod;
}
vector<array<int,2> > ff(2),gg(2);ff[0][0]=1;
k=0;
for(int i:son){
if(i!=son.back()) k=__lg(Si[i]);
else k++;
ff.resize(1<<k+1);g.resize(1<<k+1);
gg=ff;for(int j=0;j<(1<<k+1);j++) ff[j][0]=ff[j][0]*p[i]%mod,ff[j][1]=ff[j][1]*p[i]%mod;
for(int j=0;j<k+1;j++){
if(dp[i][j][0]){
for(int h=0;h<(1<<k+1);h++) if(!(h>>j&1)) {
ff[h^(1<<j)][0]=(ff[h^(1<<j)][0]+gg[h][0]*dp[i][j][0])%mod;
if((1<<j)<h) ff[h^(1<<j)][1]=(ff[h^(1<<j)][1]+gg[h][1]*dp[i][j][0])%mod;
}
}
if(dp[i][j][1]){
for(int h=0;h<(1<<j);h++) {
ff[h^(1<<j)][1]=(ff[h^(1<<j)][1]+gg[h][0]*dp[i][j][1])%mod;
}
}
}
}
for(int i=0;i<=k+1;i++){
p[x]+=ff[(1<<i)-1][1];
for(int j=0;j<i-1;j++) dp[x][j][1]=(dp[x][j][1]+ff[(1<<i)-1-(1<<j)][1])%mod;
// cerr<<i<<' '<<x<<"d "<<p[x]<<' '<<dp[3][1][1]<<'\n';
}
// cerr<<x<<"d "<<p[x]<<' '<<dp[3][1][1]<<'\n';
p[x]%=mod;
}
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<n;i++){
int x,y;scanf("%d%d",&x,&y);
S[x].eb(y);S[y].eb(x);
}
dfs(1,0);
printf("%lld\n",p[1]);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 15736kb
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: 15336kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 14740kb
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:
819688564
result:
wrong answer 1st lines differ - expected: '508800953', found: '819688564'