QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793926#9184. Team CodingMousa_Aboubaker0 24ms30780kbC++203.0kb2024-11-30 05:20:282024-11-30 05:20:28

Judging History

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

  • [2024-11-30 05:20:28]
  • 评测
  • 测评结果:0
  • 用时:24ms
  • 内存:30780kb
  • [2024-11-30 05:20:28]
  • 提交

answer

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <climits>
#include <cmath>
#include <numeric>
#include <string>
#include <bitset>
#include <assert.h>
#include <iomanip>
using namespace std;
 
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
 
const long long infl = 1e18 + 1;
const int inf = 1e9 + 1;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const long double eps = 1e-7;
const int mod = mod1;
 
int add(int a, int b) { return (a + b) % mod; }
int sub(int a, int b) { return (a - b + mod) % mod; }
int mul(int a, int b) { return (int)((long long)a * b % mod); }
int pwr(int a, int b = mod - 2)
{
	int res = 1;
	for(; b > 0; b >>= 1, a = mul(a, a))
		if(b & 1)
			res = mul(res, a);
	return res;
}
 
void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> c(n);
	for(auto &i: c)
		cin >> i;
	vector adj(n, vector<int>());
	for(int i = 1; i < n; i++)
	{
		int u;
		cin >> u;
		adj[u].push_back(i);
	}
	vector<int> dep(n, 0);
	vector up(n, vector<int>(21, -1));
	auto dfs1 = [&](auto self, int u, int d) -> void
	{
		dep[u] = d++;
		for(auto i: adj[u])
		{
			up[i][0] = u;
			self(self, i, d);
		}
	};
	dfs1(dfs1, 0, 0);
	for(int i = 1; i < 21; i++)
		for(int j = 0; j < n; j++)
			if(~up[j][i - 1])
				up[j][i] = up[up[j][i - 1]][i - 1];
	auto get_kth_par = [&](int u, int k) -> int
	{
		for(int i = 0; i < 21; i++)
			if((k >> i) & 1)
				u = up[u][i];
		return u;
	};
	int mx = *max_element(dep.begin(), dep.end());
	vector levels(mx + 1, vector<int>());
	for(int i = 0; i < n; i++)
		levels[dep[i]].push_back(i);
	int cnt1 = 0;
	for(int i = 0; i < n; i++)
		if(c[i] == c[0])
			cnt1++;
	vector<int> others;
	auto dfs2 = [&](auto self, int u) -> void
	{
		if(c[u] != c[0])
		{
			others.push_back(u);
			return;
		}
		for(auto i: adj[u])
			self(self, i);
	};
	dfs2(dfs2, 0);
	int mxxx = cnt1, mn = 0;
	int curr1 = 0, curr2 = 0;
	for(auto i: others)
	{
		for(int j = dep[i] + 1; j <= mx; j++)
		{
			int all = 0, have = 0, mxx = 0;
			for(auto x: levels[j])
			{
				if(get_kth_par(x, j - dep[i]) == i)
				{
					mxx++;
					if(c[x] != c[0])
					{
						have++;
						all++;
					}
				}
				else if(c[x] != c[0])
				{
					all++;
				}
			}
			curr2 += min(mxx - have, all - have);
			curr1 += min(mxx, all);
		}
		if(curr1 > mxxx)
		{
			mxxx = curr1;
			mn = curr2;
		}
		else if(curr1 == mxxx)
		{
			mn = min(mn, curr2);
		}
	}
	cout << mxxx << ' ' << mn;
}
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int t = 1;
	// cin >> t;
 
	while (t--) {
		solve();
		cout << (t ? "\n" : "");
	}
}


詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 12
Accepted
time: 0ms
memory: 3772kb

input:

1 1
0

output:

1 0

result:

ok single line: '1 0'

Test #2:

score: 12
Accepted
time: 0ms
memory: 3604kb

input:

5 2
0 1 0 0 0
0
1
2
3

output:

4 0

result:

ok single line: '4 0'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

10 9
6 5 6 2 5 4 5 3 4 1
0
1
2
3
4
5
6
7
8

output:

7 0

result:

wrong answer 1st lines differ - expected: '3 0', found: '7 0'

Subtask #2:

score: 0
Wrong Answer

Test #17:

score: 19
Accepted
time: 0ms
memory: 3548kb

input:

1 1
0

output:

1 0

result:

ok single line: '1 0'

Test #18:

score: 19
Accepted
time: 0ms
memory: 3832kb

input:

5 2
0 1 0 0 0
0
1
2
3

output:

4 0

result:

ok single line: '4 0'

Test #19:

score: 19
Accepted
time: 0ms
memory: 3576kb

input:

100 2
0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34...

output:

50 0

result:

ok single line: '50 0'

Test #20:

score: 19
Accepted
time: 1ms
memory: 4096kb

input:

2000 2
0 0 1 1 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0...

output:

1001 0

result:

ok single line: '1001 0'

Test #21:

score: 0
Wrong Answer
time: 24ms
memory: 30780kb

input:

100000 2
0 0 1 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0...

output:

50197 0

result:

wrong answer 1st lines differ - expected: '50198 0', found: '50197 0'

Subtask #3:

score: 0
Wrong Answer

Test #39:

score: 27
Accepted
time: 0ms
memory: 3552kb

input:

1 1
0

output:

1 0

result:

ok single line: '1 0'

Test #40:

score: 27
Accepted
time: 0ms
memory: 3612kb

input:

5 2
0 1 0 0 0
0
1
2
3

output:

4 0

result:

ok single line: '4 0'

Test #41:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

10 9
6 5 6 2 5 4 5 3 4 1
0
1
2
3
4
5
6
7
8

output:

7 0

result:

wrong answer 1st lines differ - expected: '3 0', found: '7 0'

Subtask #4:

score: 0
Wrong Answer

Test #76:

score: 23
Accepted
time: 0ms
memory: 3548kb

input:

1 1
0

output:

1 0

result:

ok single line: '1 0'

Test #77:

score: 23
Accepted
time: 0ms
memory: 3844kb

input:

5 2
0 1 0 0 0
0
1
2
3

output:

4 0

result:

ok single line: '4 0'

Test #78:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

10 9
6 5 6 2 5 4 5 3 4 1
0
1
2
3
4
5
6
7
8

output:

7 0

result:

wrong answer 1st lines differ - expected: '3 0', found: '7 0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%