제출 #296651

#제출 시각아이디문제언어결과실행 시간메모리
296651emil_physmath친구 (IOI14_friend)C++17
46 / 100
39 ms5112 KiB
#include <algorithm> #include <numeric> #include <vector> #include "friend.h" using namespace std; using llong = long long; const int maxN = 100'005; vector<int> nei[maxN]; enum Protocol { ME = 0, MY = 1, WE = 2 }; pair<int, int> SolveTree(int v, int* a) { pair<int, int> res(a[v], 0); for (int to: nei[v]) { pair<int, int> cur = SolveTree(to, a); res.first += cur.second; res.second += max(cur.first, cur.second); } return res; } // Find out best sample int findSample(int n, int a[], int host[], int prot[]){ if (n <= 10) { bool g[10][10]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) g[i][j] = false; for (int i = 1; i < n; ++i) { int j = host[i]; if (prot[i] == ME) g[i][j] = g[j][i] = true; else { for (int k = 0; k < n; ++k) if (g[j][k]) g[i][k] = g[k][i] = true; if (prot[i] == WE) g[i][j] = g[j][i] = true; } } int ans = 0; for (int mask = 1; mask < (1 << n); ++mask) { bool ok = true; int cur = 0; for (int i = 0; i < n; ++i) { if (!(mask & (1 << i))) continue; cur += a[i]; for (int j = i + 1; j < n; ++j) { if (!(mask & (1 << j))) continue; if (g[i][j]) ok = false; } } if (ok) ans = max(ans, cur); } return ans; } if (count(prot + 1, prot + n, ME) == n - 1) { for (int i = 1; i < n; ++i) nei[host[i]].push_back(i); auto p = SolveTree(0, a); return max(p.first, p.second); } if (count(prot + 1, prot + n, MY) == n - 1) return accumulate(a, a + n, 0); if (count(prot + 1, prot + n, WE) == n - 1) return *max_element(a, a + n); }

컴파일 시 표준 에러 (stderr) 메시지

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
   74 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...