# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874029 | 2023-11-16T08:06:57 Z | salmon | Friend (IOI14_friend) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int findSample(int N, int confidence[], int host[], int protocol[]){ int cas = 0; for(int i = 1; i < N; i++){ if(protocol[i] != 2){ cas = 1; } } if(cas == 0){ int big = 0; for(int i = 0; i < N; i++){ big = max(big,confidence[i]); } return big; } for(int i = 1; i < N; i++){ if(protocol[i] != 1){ cas = 2; } } if(cas == 1){ int big = 0; for(int i = 0; i < N; i++){ big += confidence[i]; } return big; } int sum = 0; for(int i = N - 1; i > 0; i--){ if(protocol[i] == 0){ if(conficence[i] > 0){ confidence[host[i]] -= confidence[i]; sum += confidence[i]; } } else if(protocol[i] == 1){ if(confidence[i] > 0){ confidence[host[i]] += confidence[i]; } else{ confidence[host[i]] = max(confidence[host[i]],confidence[i]); } } } sum += confidence[0]; return sum; }