Submission #292970

#TimeUsernameProblemLanguageResultExecution timeMemory
292970AaronNaiduFriend (IOI14_friend)C++14
46 / 100
36 ms2548 KiB
#include <bits/stdc++.h> using namespace std; int matrix[11][11]; int subTrees[2000][2]; vector<int> graph[2000]; vector<int> confs; int globMax = 0; int n; int tryItOut(vector<int> v) { for (int i = 0; i < v.size(); i++) { for (int j = i+1; j < v.size(); j++) { if (matrix[v[i]][v[j]]) { return 0; } } } int toRet = 0; for (int i = 0; i < v.size(); i++) { toRet += confs[v[i]]; } return toRet; } void doStuff(int x, vector<int> v) { if (x == n) { globMax = max(globMax, tryItOut(v)); return; } v.push_back(x); doStuff(x+1, v); v.pop_back(); doStuff(x+1, v); } int sub1(int n, int confidence[], int host[], int protocol[]) { for (int i = 1; i < n; i++) { if (protocol[i] == 0) { matrix[i][host[i]] = 1; matrix[host[i]][i] = 1; } else if (protocol[i] == 1) { for (int j = 0; j < 11; j++) { if (matrix[host[i]][j] == 1) { matrix[i][j] = 1; matrix[j][i] = 1; } } } else { for (int j = 0; j < 11; j++) { if (matrix[host[i]][j] == 1) { matrix[i][j] = 1; matrix[j][i] = 1; } } matrix[i][host[i]] = 1; matrix[host[i]][i] = 1; } } vector<int> v; doStuff(0, v); return globMax; } int maxSubtree(int node, bool canInclude) { if (subTrees[node][canInclude] > 0) { return subTrees[node][canInclude]; } if (graph[node].size() == 0) { if (canInclude) { return confs[node]; } return 0; } if (!canInclude) { int totSum = 0; for (auto i : graph[node]) { totSum += maxSubtree(i, true); } subTrees[node][canInclude] = totSum; return totSum; } int totSum1 = 0; for (auto i : graph[node]) { totSum1 += maxSubtree(i, true); } int totSum2 = confs[node]; for (auto i : graph[node]) { totSum2 += maxSubtree(i, false); } int totSum = max(totSum1, totSum2); subTrees[node][canInclude] = totSum; return totSum; } int findSample(int N, int confidence[], int host[], int protocol[]) { n = N; int confSum = 0; int confMax = 0; for (int i = 0; i < n; i++) { confs.push_back(confidence[i]); confSum += confs[i]; confMax = max(confMax, confs[i]); } if (n <= 10) { n = N; return sub1(n, confidence, host, protocol); } if (protocol[1] == 1) { return confSum; } if (protocol[1] == 2) { return confMax; } for (int i = 1; i < n; i++) { graph[host[i]].push_back(i); //graph[i].push_back(host[i]); } return maxSubtree(0, true); }

Compilation message (stderr)

friend.cpp: In function 'int tryItOut(std::vector<int>)':
friend.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
friend.cpp:14:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for (int j = i+1; j < v.size(); j++)
      |                           ~~^~~~~~~~~~
friend.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 0; i < v.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...