QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793932 | #9184. Team Coding | Mousa_Aboubaker | 0 | 30ms | 30784kb | C++20 | 3.1kb | 2024-11-30 05:27:02 | 2024-11-30 05:27:03 |
Judging History
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)
{
curr1 = 1, curr2 = 0;
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++;
}
}
if(mxx == 0)
break;
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: 3552kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #2:
score: 12
Accepted
time: 0ms
memory: 3480kb
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: 3776kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
8 0
result:
wrong answer 1st lines differ - expected: '3 0', found: '8 0'
Subtask #2:
score: 0
Time Limit Exceeded
Test #17:
score: 19
Accepted
time: 0ms
memory: 3552kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #18:
score: 19
Accepted
time: 0ms
memory: 3580kb
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: 3832kb
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: 0ms
memory: 4204kb
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: 19
Accepted
time: 30ms
memory: 30784kb
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:
50198 0
result:
ok single line: '50198 0'
Test #22:
score: 19
Accepted
time: 0ms
memory: 3792kb
input:
99 2 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 65 53 0 0 41 0 59 26 87 78 62 23 52 0 97 0 0 90 0 4 77 55 0 73 45 0 19 92 32 0 0 0 82 48 60 54 72...
output:
2 0
result:
ok single line: '2 0'
Test #23:
score: 19
Accepted
time: 14ms
memory: 3960kb
input:
1999 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
2 0
result:
ok single line: '2 0'
Test #24:
score: 0
Time Limit Exceeded
input:
99999 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
result:
Subtask #3:
score: 0
Wrong Answer
Test #39:
score: 27
Accepted
time: 0ms
memory: 3840kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #40:
score: 27
Accepted
time: 0ms
memory: 3848kb
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: 3548kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
8 0
result:
wrong answer 1st lines differ - expected: '3 0', found: '8 0'
Subtask #4:
score: 0
Wrong Answer
Test #76:
score: 23
Accepted
time: 0ms
memory: 3836kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #77:
score: 23
Accepted
time: 0ms
memory: 3500kb
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: 3492kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
8 0
result:
wrong answer 1st lines differ - expected: '3 0', found: '8 0'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%