Submission #1037351

#TimeUsernameProblemLanguageResultExecution timeMemory
1037351onbertFriend (IOI14_friend)C++17
50 / 100
24 ms10092 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn], t[maxn]; vector<int> adj[maxn][2]; int dp[maxn][3]; void dfs(int u) { for (int i=0;i<=1;i++) for (int v:adj[u][i]) dfs(v); int pt = 0, cur = 0; for (int v:adj[u][0]) cur += dp[v][2]; for (int v:adj[u][1]) cur += dp[v][1]; dp[u][0] = cur; for (int v:adj[u][0]) { while (pt<adj[u][1].size() && adj[u][1][pt] < v) cur += dp[adj[u][1][pt]][2] - dp[adj[u][1][pt]][1], pt++; dp[u][0] = max(cur, dp[u][0]); cur += dp[v][1] - dp[v][2]; } while (pt<adj[u][1].size()) cur += dp[adj[u][1][pt]][2] - dp[adj[u][1][pt]][1], pt++; dp[u][0] = max(cur, dp[u][0]); dp[u][1] = 0; for (int v:adj[u][0]) dp[u][1] += dp[v][2]; for (int v:adj[u][1]) dp[u][1] += dp[v][1]; dp[u][2] = a[u]; for (int v:adj[u][0]) dp[u][2] += dp[v][1]; for (int v:adj[u][1]) dp[u][2] += dp[v][2]; dp[u][2] = max({dp[u][0], dp[u][1], dp[u][2]}); } int findSample(int N, int confidence[], int host[], int protocol[]){ n = N; for (int i=0;i<n;i++) a[i] = confidence[i]; t[0] = 0; for (int i=1;i<n;i++) t[i] = protocol[i]; for (int i=1;i<n;i++) adj[host[i]][t[i]].push_back(i); dfs(0); // for (int j=0;j<=2;j++) { // cout << j << endl; // for (int i=0;i<n;i++) cout << dp[i][j] << " "; cout << endl; // } return dp[0][2]; }

Compilation message (stderr)

friend.cpp: In function 'void dfs(int)':
friend.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         while (pt<adj[u][1].size() && adj[u][1][pt] < v) cur += dp[adj[u][1][pt]][2] - dp[adj[u][1][pt]][1], pt++;
      |                ~~^~~~~~~~~~~~~~~~~
friend.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     while (pt<adj[u][1].size()) cur += dp[adj[u][1][pt]][2] - dp[adj[u][1][pt]][1], pt++;
      |            ~~^~~~~~~~~~~~~~~~~
#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...