QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883450 | #9184. Team Coding | I_love_Riley_Andersen | 0 | 155ms | 53916kb | C++17 | 3.5kb | 2025-02-05 16:26:18 | 2025-02-05 16:26:20 |
Judging History
answer
#include"bits/stdc++.h"
#include"ext/pb_ds/tree_policy.hpp"
#include"ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define FOR(i,a,b)for(int i=a;i<b;i++)
#define F0R(i,a)FOR(i,0,a)
#define ROF(i,a,b)for(int i=b-1;a<=i;i--)
#define R0F(i,a)ROF(i,0,a)
#define rep(a)F0R(_,a)
#define each(a,x)for(auto&a:x)
#define all(a)begin(a),end(a)
#define sz(x)int(size(x))
#define lla(x)rbegin(x),rend(x)
#define SUM(a)accumulate(all(a),0ll)
#define SUMM(a,b)accumulate(a,a+b,0ll)
#define MAX(a)*max_element(all(a))
#define MAXX(a,b)*max_element(a,a+b)
#define MIN(a)*min_element(all(a))
#define MINN(a,b)*min_element(a,a+b)
#define con const int
#define lwb lower_bound
#define upb upper_bound
#define bry binary_search
#ifdef LOCAL
#define print(x)cout<<x;
#else
#define print(...)
#endif
#define debug(x)print(#x<<" = "<<x<<endl)
using ld=long double;
using ll=long long;
using str=string;
template<class T>using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>using omset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>T minn(T a){return a;}
template<class T,class...Args>T minn(T a,Args... args){return min(a,minn(args...));}
template<class T>T maxx(T a){return a;}
template<class T,class...Args>T maxx(T a,Args... args){return max(a,maxx(args...));}
#define SMIN(a,b...)a=min(a,minn(b))
#define SMAX(a,b...)a=max(a,maxx(b))
void fileset(str a){assert(nullptr!=freopen((a+".in").c_str(),"r",stdin)&&nullptr!=freopen((a+".out").c_str(),"w",stdout));}
con mxN = 2e5 + 5;
map<int,int> cntDepth[mxN];
vector<int> teamies[mxN];
vector<int> aj[mxN];
int ent[mxN];
int ext[mxN];
int col[mxN];
int dep[mxN];
int ans = INT_MIN;
int bbl = INT_MAX;
int tr;
int isInside(int u, int v){
return ent[u] <= ent[v] && ext[v] <= ext[u];
}
void preCalc(int u, int d){
dep[u] = d, ent[u] = tr ++;
each (v, aj[u]){
preCalc(v, d + 1);
}
ext[u] = tr ++;
}
void solve(int u){
cntDepth[u][dep[u]] = 1;
each (v, aj[u]){
solve(v);
if (sz(cntDepth[v]) > sz(cntDepth[u])){
swap(cntDepth[v], cntDepth[u]);
}
each (pr, cntDepth[v]){
auto [depth, cnt] = pr;
cntDepth[u][depth] += cnt;
}
}
int loc = 1;
int swp = 0;
int cnt = 0;
int n = sz(teamies[col[u]]);
F0R (i, n){
int v = teamies[col[u]][i];
if (dep[u] ^ dep[v]){
if (isInside(u, v)) loc ++;
else cnt ++;
if (i < n - 1 && dep[v] ^ dep[teamies[col[u]][i + 1]]){
if (cntDepth[u].count(dep[v])){
int tmp = min(cnt, cntDepth[u][dep[v]]);
loc += tmp, swp += tmp;
}
cnt = 0;
}
}
}
if (loc > ans){
ans = loc, bbl = swp;
} else if (loc == ans){
bbl = min(bbl, swp);
}
}
int main(){
int N, K;
cin >> N >> K;
F0R (i, N){
cin >> col[i];
}
FOR (i, 1, N){
int B;
cin >> B;
aj[B].push_back(i);
}
preCalc(0, 0);
F0R (i, N){
teamies[col[i]].push_back(i);
}
F0R (i, K){
sort(all(teamies[i]),[](int i, int j){
return dep[i] < dep[j];
});
teamies[col[i]].push_back(N);
}
solve(0);
cout << ans << ' ' << bbl << endl;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 12
Accepted
time: 0ms
memory: 23452kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #2:
score: 12
Accepted
time: 2ms
memory: 24752kb
input:
5 2 0 1 0 0 0 0 1 2 3
output:
4 0
result:
ok single line: '4 0'
Test #3:
score: 12
Accepted
time: 4ms
memory: 24664kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
3 0
result:
ok single line: '3 0'
Test #4:
score: 12
Accepted
time: 2ms
memory: 25344kb
input:
15 8 3 6 7 6 7 6 6 0 6 7 3 6 2 3 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13
output:
6 0
result:
ok single line: '6 0'
Test #5:
score: 12
Accepted
time: 2ms
memory: 24976kb
input:
7 3 1 1 1 2 1 0 1 0 1 2 3 4 5
output:
5 0
result:
ok single line: '5 0'
Test #6:
score: 12
Accepted
time: 2ms
memory: 23520kb
input:
8 6 1 4 0 1 3 0 4 5 0 1 2 3 4 5 6
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 12
Accepted
time: 2ms
memory: 25084kb
input:
100 97 73 42 17 20 20 71 6 52 18 93 34 27 96 35 77 27 46 62 23 83 12 13 91 61 82 0 59 82 6 67 24 37 4 61 2 6 31 12 21 37 47 39 44 85 92 16 66 39 48 69 57 62 75 7 87 68 89 44 77 69 12 6 19 31 30 2 14 90 30 37 67 5 88 53 59 3 1 45 75 82 59 27 51 0 85 65 57 75 74 53 35 44 87 86 77 52 35 23 87 87 0 1 2 ...
output:
4 0
result:
ok single line: '4 0'
Test #8:
score: 12
Accepted
time: 13ms
memory: 24516kb
input:
2000 28 13 0 11 21 0 3 7 0 2 10 25 17 13 21 19 12 9 17 21 12 12 17 9 2 21 11 0 13 9 4 6 18 4 14 22 26 20 24 18 5 0 27 13 15 4 8 9 27 17 24 13 4 27 3 6 11 24 18 10 5 22 8 7 4 26 22 18 27 1 0 1 21 23 1 10 2 1 21 7 25 24 21 25 23 22 0 14 5 3 6 19 8 7 4 7 27 27 19 26 18 17 3 1 12 8 1 10 18 22 23 25 14 2...
output:
85 0
result:
ok single line: '85 0'
Test #9:
score: 12
Accepted
time: 155ms
memory: 53112kb
input:
100000 59066 10203 30163 14221 32641 57632 52742 51576 33938 17167 56268 10461 37834 58393 19522 10361 4859 50498 54209 40282 44610 7141 54240 58622 15568 57813 20977 23646 51685 16859 23152 37761 20080 6279 48735 39054 5181 35803 38656 7011 54044 4665 29269 39955 44267 6927 1328 56776 24684 2653 10...
output:
10 0
result:
ok single line: '10 0'
Test #10:
score: 12
Accepted
time: 4ms
memory: 23544kb
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 #11:
score: 12
Accepted
time: 110ms
memory: 25836kb
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 #12:
score: 0
Time Limit Exceeded
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:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #17:
score: 19
Accepted
time: 4ms
memory: 24820kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #18:
score: 19
Accepted
time: 4ms
memory: 23784kb
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: 4ms
memory: 24684kb
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: 105ms
memory: 24704kb
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
Time Limit Exceeded
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:
result:
Subtask #3:
score: 0
Wrong Answer
Test #39:
score: 27
Accepted
time: 3ms
memory: 24068kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #40:
score: 27
Accepted
time: 4ms
memory: 23536kb
input:
5 2 0 1 0 0 0 0 1 2 3
output:
4 0
result:
ok single line: '4 0'
Test #41:
score: 27
Accepted
time: 2ms
memory: 24640kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
3 0
result:
ok single line: '3 0'
Test #42:
score: 27
Accepted
time: 3ms
memory: 24768kb
input:
15 8 3 6 7 6 7 6 6 0 6 7 3 6 2 3 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13
output:
6 0
result:
ok single line: '6 0'
Test #43:
score: 27
Accepted
time: 4ms
memory: 23644kb
input:
7 3 1 1 1 2 1 0 1 0 1 2 3 4 5
output:
5 0
result:
ok single line: '5 0'
Test #44:
score: 27
Accepted
time: 1ms
memory: 24628kb
input:
8 6 1 4 0 1 3 0 4 5 0 1 2 3 4 5 6
output:
2 0
result:
ok single line: '2 0'
Test #45:
score: 27
Accepted
time: 2ms
memory: 25456kb
input:
100 97 73 42 17 20 20 71 6 52 18 93 34 27 96 35 77 27 46 62 23 83 12 13 91 61 82 0 59 82 6 67 24 37 4 61 2 6 31 12 21 37 47 39 44 85 92 16 66 39 48 69 57 62 75 7 87 68 89 44 77 69 12 6 19 31 30 2 14 90 30 37 67 5 88 53 59 3 1 45 75 82 59 27 51 0 85 65 57 75 74 53 35 44 87 86 77 52 35 23 87 87 0 1 2 ...
output:
4 0
result:
ok single line: '4 0'
Test #46:
score: 27
Accepted
time: 125ms
memory: 53916kb
input:
100000 59066 10203 30163 14221 32641 57632 52742 51576 33938 17167 56268 10461 37834 58393 19522 10361 4859 50498 54209 40282 44610 7141 54240 58622 15568 57813 20977 23646 51685 16859 23152 37761 20080 6279 48735 39054 5181 35803 38656 7011 54044 4665 29269 39955 44267 6927 1328 56776 24684 2653 10...
output:
10 0
result:
ok single line: '10 0'
Test #47:
score: 27
Accepted
time: 0ms
memory: 24612kb
input:
100 100 14 93 75 59 44 2 61 56 89 75 70 53 50 78 16 1 48 32 52 21 84 12 75 52 39 89 88 29 71 69 18 0 19 20 66 23 55 99 42 63 46 2 93 23 40 13 64 32 51 47 34 13 95 48 23 55 20 21 87 46 62 7 69 98 66 77 66 16 85 70 2 51 9 9 37 89 85 72 59 13 14 69 4 78 56 84 63 40 35 90 93 44 66 32 25 80 93 99 40 39 0...
output:
4 0
result:
ok single line: '4 0'
Test #48:
score: 27
Accepted
time: 3ms
memory: 24432kb
input:
2000 2000 68 392 1223 140 162 1107 45 1894 1544 255 840 1756 173 1277 1932 1230 1774 932 1637 935 1554 1296 917 158 707 1350 297 1763 1374 1778 637 1079 726 1514 485 678 288 1595 1529 296 414 1803 816 1419 962 1234 521 277 1353 1679 1472 249 1083 1539 442 1925 442 114 116 790 1246 649 15 145 1622 36...
output:
6 0
result:
ok single line: '6 0'
Test #49:
score: 27
Accepted
time: 108ms
memory: 53536kb
input:
100000 100000 41728 93320 38571 44676 59528 37978 81336 71690 19433 62851 10920 32382 57235 11051 54769 96948 26321 8339 26066 61016 79074 40324 13106 94743 16700 60377 60008 60349 77853 65660 4887 16582 91933 4573 43258 30974 68341 21985 25073 6706 28676 32064 29269 78970 28685 53456 23597 67768 65...
output:
8 0
result:
ok single line: '8 0'
Test #50:
score: 27
Accepted
time: 5ms
memory: 24012kb
input:
10 2 1 1 1 1 0 1 1 1 1 0 8 8 8 3 9 0 9 0 0
output:
8 0
result:
ok single line: '8 0'
Test #51:
score: 27
Accepted
time: 2ms
memory: 24200kb
input:
12 8 1 4 0 5 4 1 7 1 2 6 3 1 0 10 9 10 11 7 0 2 0 0 10
output:
4 0
result:
ok single line: '4 0'
Test #52:
score: 0
Wrong Answer
time: 2ms
memory: 23856kb
input:
11 7 2 2 5 0 6 2 5 5 5 5 4 2 10 5 0 7 10 0 7 10 0
output:
4 2
result:
wrong answer 1st lines differ - expected: '3 0', found: '4 2'
Subtask #4:
score: 0
Wrong Answer
Test #76:
score: 23
Accepted
time: 2ms
memory: 23592kb
input:
1 1 0
output:
1 0
result:
ok single line: '1 0'
Test #77:
score: 23
Accepted
time: 2ms
memory: 24640kb
input:
5 2 0 1 0 0 0 0 1 2 3
output:
4 0
result:
ok single line: '4 0'
Test #78:
score: 23
Accepted
time: 1ms
memory: 25512kb
input:
10 9 6 5 6 2 5 4 5 3 4 1 0 1 2 3 4 5 6 7 8
output:
3 0
result:
ok single line: '3 0'
Test #79:
score: 23
Accepted
time: 0ms
memory: 25196kb
input:
15 8 3 6 7 6 7 6 6 0 6 7 3 6 2 3 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13
output:
6 0
result:
ok single line: '6 0'
Test #80:
score: 23
Accepted
time: 1ms
memory: 24700kb
input:
7 3 1 1 1 2 1 0 1 0 1 2 3 4 5
output:
5 0
result:
ok single line: '5 0'
Test #81:
score: 23
Accepted
time: 2ms
memory: 23684kb
input:
8 6 1 4 0 1 3 0 4 5 0 1 2 3 4 5 6
output:
2 0
result:
ok single line: '2 0'
Test #82:
score: 23
Accepted
time: 3ms
memory: 23512kb
input:
100 97 73 42 17 20 20 71 6 52 18 93 34 27 96 35 77 27 46 62 23 83 12 13 91 61 82 0 59 82 6 67 24 37 4 61 2 6 31 12 21 37 47 39 44 85 92 16 66 39 48 69 57 62 75 7 87 68 89 44 77 69 12 6 19 31 30 2 14 90 30 37 67 5 88 53 59 3 1 45 75 82 59 27 51 0 85 65 57 75 74 53 35 44 87 86 77 52 35 23 87 87 0 1 2 ...
output:
4 0
result:
ok single line: '4 0'
Test #83:
score: 23
Accepted
time: 12ms
memory: 25440kb
input:
2000 28 13 0 11 21 0 3 7 0 2 10 25 17 13 21 19 12 9 17 21 12 12 17 9 2 21 11 0 13 9 4 6 18 4 14 22 26 20 24 18 5 0 27 13 15 4 8 9 27 17 24 13 4 27 3 6 11 24 18 10 5 22 8 7 4 26 22 18 27 1 0 1 21 23 1 10 2 1 21 7 25 24 21 25 23 22 0 14 5 3 6 19 8 7 4 7 27 27 19 26 18 17 3 1 12 8 1 10 18 22 23 25 14 2...
output:
85 0
result:
ok single line: '85 0'
Test #84:
score: 23
Accepted
time: 3ms
memory: 25100kb
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 #85:
score: 23
Accepted
time: 104ms
memory: 24452kb
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 #86:
score: 23
Accepted
time: 2ms
memory: 24212kb
input:
100 100 14 93 75 59 44 2 61 56 89 75 70 53 50 78 16 1 48 32 52 21 84 12 75 52 39 89 88 29 71 69 18 0 19 20 66 23 55 99 42 63 46 2 93 23 40 13 64 32 51 47 34 13 95 48 23 55 20 21 87 46 62 7 69 98 66 77 66 16 85 70 2 51 9 9 37 89 85 72 59 13 14 69 4 78 56 84 63 40 35 90 93 44 66 32 25 80 93 99 40 39 0...
output:
4 0
result:
ok single line: '4 0'
Test #87:
score: 23
Accepted
time: 4ms
memory: 25088kb
input:
2000 2000 68 392 1223 140 162 1107 45 1894 1544 255 840 1756 173 1277 1932 1230 1774 932 1637 935 1554 1296 917 158 707 1350 297 1763 1374 1778 637 1079 726 1514 485 678 288 1595 1529 296 414 1803 816 1419 962 1234 521 277 1353 1679 1472 249 1083 1539 442 1925 442 114 116 790 1246 649 15 145 1622 36...
output:
6 0
result:
ok single line: '6 0'
Test #88:
score: 0
Wrong Answer
time: 1ms
memory: 23908kb
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:
3 1
result:
wrong answer 1st lines differ - expected: '2 0', found: '3 1'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%