QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#229355#7607. The Doubling Game 2FamiglistmoWA 0ms15548kbC++142.5kb2023-10-28 15:58:002023-10-28 15:58:01

Judging History

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

  • [2023-10-28 15:58:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15548kb
  • [2023-10-28 15:58:00]
  • 提交

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<ll> f(4),g(4);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<ll,2> > ff(4),gg(4);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';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 14892kb

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: 15548kb

input:

1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 15492kb

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'