QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236035#7607. The Doubling Game 2qwqwfWA 8ms25228kbC++141.6kb2023-11-03 15:43:372023-11-03 15:43:37

Judging History

你现在查看的是最新测评结果

  • [2023-11-03 15:43:37]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:25228kb
  • [2023-11-03 15:43:37]
  • 提交

answer

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
//#define int ll
using namespace std;
const int N=3e5+20,M=1e6+20,mod=1e9+7;
vector<int> f[N],g[N],e[N];int n,h[N];
inline bool cmp(int x,int y){return (int)f[x].size()<(int)f[y].size();}
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
void dfs(int u,int fa){
	for(int v:e[u]) if(v!=fa) dfs(v,u);
	sort(e[u].begin(),e[u].end(),cmp);
	int sz=1;vector<int> U(2),D(2);
	U[0]=1;
	for(int v:e[u]) if(v!=fa){
		vector<int> F(1<<(f[v].size()+1)),G(1<<(f[v].size()+1));
		for(int s=0;s<sz;s++){
			add(F[s],1ll*U[s]*h[v]%mod);
			add(G[s],1ll*D[s]*h[v]%mod);
			for(int x=0;x<f[v].size();x++){
				if(s>>x&1) continue;
				add(F[s|(1<<x)],1ll*U[s]*f[v][x]%mod);
				if(s>(1<<x)) add(G[s|(1<<x)],1ll*D[s]*f[v][x]%mod);
				else add(G[s|(1<<x)],1ll*U[s]*g[v][x]%mod);
			}
		}
		swap(U,F);swap(D,G);
		sz=(1<<f[v].size());
		vector<int>().swap(F);vector<int>().swap(G);
	}
	sz=log2(sz);
	f[u].resize(sz+1);g[u].resize(sz+1);
	for(int i=0;i<=sz;i++){
		int s=(1<<i)-1;
		add(h[u],U[s]);add(h[u],D[s]);
		add(f[u][i],U[s]);add(g[u][i],U[s]);
		for(int j=0;j<i-1;j++) add(g[u][i],U[s^(1<<j)]),add(g[u][i],D[s^(1<<j)]);
	}
	while(!f[u].back()&&!g[u].back()) f[u].pop_back(),g[u].pop_back();
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1,u,v;i<n;i++) cin>>u>>v,e[u].pb(v),e[v].pb(u);
	dfs(1,0);
	cout<<h[1]<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 24708kb

input:

5
1 2
1 3
1 4
4 5

output:

21

result:

ok single line: '21'

Test #2:

score: 0
Accepted
time: 4ms
memory: 24624kb

input:

1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 25228kb

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:

516012349

result:

wrong answer 1st lines differ - expected: '508800953', found: '516012349'