QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#240989 | #7607. The Doubling Game 2 | liujinhan | WA | 4ms | 37732kb | C++14 | 1.6kb | 2023-11-05 21:38:12 | 2023-11-05 21:38:13 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N=6e5+10;
const ll mod=1e9+7;
vector<ll>f[N],g[N];
ll s[N];
int n,h[N],l[N],t[N],ct,m;
struct node{
ll x,y;
}bb[N];
bool cmp(node a,node b){return a.y<b.y;}
void add(int u,int v){t[++ct]=v,l[ct]=h[u],h[u]=ct;}
void dfs(int x,int fa){
for(int i=h[x];i;i=l[i]) if(t[i]!=fa) dfs(t[i],x);
m=0;
for(int i=h[x];i;i=l[i]) if(t[i]!=fa) bb[++m]={t[i],(ll)f[t[i]].size()};
sort(bb+1,bb+m+1,cmp);
vector<ll>a,b;
a.pb(1),b.pb(0);
for(ll i=1,j,k;i<=m;i++){
j=bb[i].x,k=f[j].size();
vector<ll> c(1<<k),d(1<<k);
for(ll o=0;o<a.size();o++){
(c[o]+=a[o]*s[j]%mod)%=mod;
(d[o]+=b[o]*s[j]%mod)%=mod;
for(ll l=0;l<k;l++)if(!((o>>l)&1)){
(c[o|(1<<l)]+=a[o]*f[j][l]%mod)%=mod;
if(o>(1<<l)) (d[o|(1<<l)]+=b[o]*f[j][l]%mod)%=mod;
else (d[o|(1<<l)]+=a[o]*g[j][l]%mod)%=mod;
}
}
a.swap(c),b.swap(d);
}
ll k=f[bb[m].x].size()+1;
f[x].resize(k),g[x].resize(k);
for(ll i=0,j;i<k;i++){
j=(1<<i)-1;
(f[x][i]+=a[j])%=mod,(g[x][i]+=a[j])%=mod;
for(ll l=0;l<k-2;l++) (g[x][i]+=a[j^(1<<l)])%=mod;
for(ll l=0;l<k-2;l++) (g[x][i]+=b[j^(1<<l)])%=mod;
(s[x]+=a[j]+b[j])%=mod;
}
while(f[x].back()==0&&g[x].back()==0) f[x].pop_back(),g[x].pop_back();
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v),add(v,u);
}
dfs(1,0);
printf("%lld",s[1]);
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 37732kb
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: 37156kb
input:
1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 37220kb
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:
868624665
result:
wrong answer 1st lines differ - expected: '508800953', found: '868624665'