QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232784#7607. The Doubling Game 2sinsop90WA 12ms47776kbC++142.3kb2023-10-30 22:05:522023-10-30 22:05:52

Judging History

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

  • [2023-10-30 22:05:52]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:47776kb
  • [2023-10-30 22:05:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 5, mod = 1e9 + 7;
int T[maxn], n;
vector<int> vec[maxn], UPF[maxn], DOWF[maxn];
//UPF:µ½faµÄ±ßÊÇÎÒ×Ô¼º´«ÉÏÈ¥
//DOWF:µ½faµÄ±ßÊÇfa´«ÏÂÀ´ 
void add(int &x, int y) {
	x += y;
	if(x >= mod) x -= y;
}
void dfs(int now, int f) {
	for(int v : vec[now]) if(v != f) dfs(v, now);
	sort(vec[now].begin(), vec[now].end(), [&](int a, int b) {return UPF[a].size() < UPF[b].size();});
	int sz = 1;
	vector<int> UP(2), DOW(2);
	UP[0] = 1;
	//UP:¶ù×ÓÈ«²¿ÏòÉÏ´«
	//DOW:ÎÒÏòÏ´«ÁË 
	for(int v : vec[now]) {
		if(v == f) continue;
		vector<int> F(1 << UPF[v].size() + 1), G(1 << UPF[v].size() + 1);
		//F:¶Ô±êUP
		//G:¶Ô±êDOW 
		for(int S = 0;S < sz;S ++) {
			add(F[S], 1ll * UP[S] * T[v] % mod);
			add(G[S], 1ll * DOW[S] * T[v] % mod);
			for(int x = 0;x < UPF[v].size();x++) {
				if(S >> x & 1) continue;
				add(F[S | (1 << x)], 1ll * UPF[v][x] * UP[S] % mod);
				if(S > (1 << x)) add(G[S | (1 << x)], 1ll * UPF[v][x] * DOW[S] % mod);
				else add(G[S | (1 << x)], 1ll * DOWF[v][x] * UP[S] % mod);
			}
		}
//		cout << now << " " << v << " " << T[v] << '\n';
//		for(int X : G) cout << X << " ";
//		cout << '\n';
		swap(F, UP), swap(G, DOW);
		
//		cout << now << " " << v << " " << UPF[v].size() << '\n'; 
		sz = (1 << UPF[v].size());
		vector<int>().swap(F), vector<int>().swap(G); 
	}
//	cout << now << '\n';
//	for(int X : DOW) cout << X << " ";
//	cout << '\n';
//	cout << now << " " << sz << " " << log2(sz) + 1 << '\n' ;
	sz = log2(sz);
	UPF[now].resize(sz + 1), DOWF[now].resize(sz + 1);
	for(int i = 0;i <= sz;i++) {
		int S = (1 << i) - 1;
		add(T[now], UP[S]), add(T[now], DOW[S]);
//		cout << now << " " << i << " " << S << " " << UP[S] << '\n';
		add(UPF[now][i], UP[S]), add(DOWF[now][i], UP[S]);
		for(int j = 0;j <= i - 2;j++) add(DOWF[now][j], (UP[S ^ (1 << j)] + DOW[S ^ (1 << j)]) % mod);
	}
//	cout << now << " " << DOWF[now][0] << '\n';
	while(!UPF[now].back() && !DOWF[now].back()) UPF[now].pop_back(), DOWF[now].pop_back();
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1, u, v;i < n;i++) {
		cin >> u >> v;
		vec[u].push_back(v), vec[v].push_back(u);
	}
	dfs(1, 0);
	cout << T[1] << '\n';
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 47000kb

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

input:

1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 47776kb

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:

734625247

result:

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