Submission #1018010

#TimeUsernameProblemLanguageResultExecution timeMemory
1018010n3rm1nFriend (IOI14_friend)C++17
46 / 100
21 ms8284 KiB
#include <bits/stdc++.h> #define endl '\n' #include "friend.h" using namespace std; long long ans = 0; long long are[1005][1005], c[1005]; long long N, used[1005]; void check() { vector < int > g; long long all = 0; for (int i = 0; i < N; ++ i) { if(used[i]) { g.push_back(i); all += c[i]; } } for (int i = 0; i < g.size(); ++ i) { for (int j = i+1; j < g.size(); ++ j) if(are[g[i]][g[j]])return; } ans = max(ans, all); } void gen(int pos) { if(pos == N) { check(); return; } used[pos] = 0; gen(pos+1); used[pos] = 1; gen(pos+1); } int cntp[4]; vector < int > g[1005]; int visited[1005]; int dfs(int beg) { visited[beg] = 1; int maxx = c[beg]; int nb; for (int i = 0; i < g[beg].size(); ++ i) { nb = g[beg][i]; if(!visited[nb])maxx = max(maxx, dfs(nb)); } return maxx; } int result = 0, dp[1005][2]; void dfs_dp(int beg) { visited[beg] = 1; dp[beg][0] = 0; dp[beg][1] = c[beg]; int nb; for (int i = 0; i < g[beg].size(); ++ i) { nb = g[beg][i]; if(!visited[nb]) { dfs_dp(nb); dp[beg][0] += max(dp[nb][1], dp[nb][0]); dp[beg][1] += dp[nb][0]; } } result = max(result, dp[beg][1]); result = max(result, dp[beg][0]); } int findSample(int n, int confidence[], int host[], int protocol[]) { N = n; for (int i = 0; i < n; ++ i) cntp[protocol[i]] ++; for (int i = 0; i < n; ++ i) c[i] = confidence[i]; if(n <= 10) { c[0] = confidence[0]; for (int i = 1; i < n; ++ i) { c[i] = confidence[i]; if(protocol[i] == 0) { g[i].push_back(host[i]); g[host[i]].push_back(i); are[i][host[i]] = 1; are[host[i]][i] = 1; } else { for (int j = 0; j < n; ++ j) { if(are[j][host[i]]) { g[i].push_back(j); g[j].push_back(i); are[i][j] = 1; are[j][i] = 1; } } if(protocol[i] == 2) { g[i].push_back(host[i]); g[host[i]].push_back(i); are[i][host[i]] = 1; are[host[i]][i] = 1; } } } gen(0); return ans; } if(cntp[2] == n-1) { long long maxx = 0; for (int i = 0; i < n; ++ i) { maxx = max(maxx, 1LL * confidence[i]); } return maxx; } if(cntp[1] == n-1) { long long ans = 0; for (int i = 0; i < n; ++ i) { if(!visited[i])ans += dfs(i); } return ans; } c[0] = confidence[0]; for (int i = 1; i < n; ++ i) { c[i] = confidence[i]; if(protocol[i] == 0) { g[i].push_back(host[i]); g[host[i]].push_back(i); are[i][host[i]] = 1; are[host[i]][i] = 1; } } for (int i = 0; i < n; ++ i) if(!visited[i])dfs_dp(i); return result; }

Compilation message (stderr)

friend.cpp: In function 'void check()':
friend.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < g.size(); ++ i)
      |                     ~~^~~~~~~~~~
friend.cpp:22:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int j = i+1; j < g.size(); ++ j)
      |                           ~~^~~~~~~~~~
friend.cpp: In function 'int dfs(int)':
friend.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < g[beg].size(); ++ i)
      |                     ~~^~~~~~~~~~~~~~~
friend.cpp: In function 'void dfs_dp(int)':
friend.cpp:63:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i = 0; i < g[beg].size(); ++ i)
      |                     ~~^~~~~~~~~~~~~~~
#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...