Submission #50519

#TimeUsernameProblemLanguageResultExecution timeMemory
50519mirbek01Friend (IOI14_friend)C++17
35 / 100
3 ms848 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 2; int n, g[N][N], dp[N], ar[N], b[N]; vector <int> G[N]; void dfs(int v, int pr){ int ch = 0; for(int to : G[v]){ if(to == pr) continue; dfs(to, v); ch += dp[to]; if(pr != -1) b[pr] += dp[to]; } dp[v] = max(b[v] + ar[v], ch); } // Find out best sample int findSample(int N,int confidence[],int host[],int protocol[]){ n = N; int ans = 0; if(n <= 1){ for(int i = 1; i < n; i ++){ if(protocol[i]){ for(int j = 0; j < n; j ++){ if(g[host[i]][j]) g[j][i] = g[i][j] = 1; } } if(protocol[i] != 1){ g[i][host[i]] = g[host[i]][i] = 1; } } for(int mask = 0; mask < (1 << n); mask ++){ vector <int> v; int sum = 0; for(int i = 0; i < n; i ++){ int bit = (1 << i) & mask; if(bit){ sum += confidence[i]; v.push_back(i); } } bool fl = 1; for(int i = 0; i < v.size(); i ++){ for(int j = i + 1; j < v.size(); j ++){ if(g[v[i]][v[j]]){ fl = 0; } } } if(fl) ans = max(ans, sum); } } else { if(protocol[n - 1] == 2){ for(int i = 0; i < n; i ++) ans = max(ans, confidence[i]); } else if(protocol[n - 1]){ for(int i = 0; i < n; i ++){ ans += confidence[i]; } } else { for(int i = 1; i < n; i ++){ G[host[i]].push_back(i); G[i].push_back(host[i]); } for(int i = 0; i < n; i ++) ar[i] = confidence[i]; dfs(0, -1); ans = dp[0]; } } return ans; }

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:52:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                   for(int i = 0; i < v.size(); i ++){
                                  ~~^~~~~~~~~~
friend.cpp:53:46: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for(int j = i + 1; j < v.size(); j ++){
                                            ~~^~~~~~~~~~
#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...