Submission #808965

#TimeUsernameProblemLanguageResultExecution timeMemory
808965OrazBFriend (IOI14_friend)C++14
0 / 100
47 ms4320 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const int N = 1e3+5; int c[N], dp[N][2], vis[N][N][2]; ll mx = 0; vector<int> E[N]; void bit(int x, int n, int A[]){ if (x == n){ ll sum = 0; for (int i = 0; i < n; i++){ if (c[i]){ for (auto j : E[i]) if (c[j]) return; sum += A[i]; } } mx = max(mx, sum); return; } for (int i = 0; i < 2; i++){ c[x] = i; bit(x+1, n, A); } } void dfs(int nd, int pr, int A[]){ int a = 0; for (auto i : E[nd]){ if (i == pr) continue; dfs(i, nd, A); a += dp[i][0]; dp[nd][0] += max(dp[i][1], dp[i][0]); } dp[nd][1] = a+A[nd]; } int findSample(int n, int A[], int u[], int v[]){ int sub0 = 0, sub1 = 0, sub2 = 0; int sum = 0; for (int i = 0; i < n; i++) sum += A[i]; dp[0][1] = A[1]; vis[0][0][1] = 1; for (int i = 1; i < n; i++){ if (v[i] == 2) sub2 = 1; if (v[i] == 0) sub0 = 1; if (v[i] == 1) sub1 = 1; if (v[i] == 1 or v[i] == 2){ int a = 0; for (auto j : E[u[i]]){ E[i].pb(j); E[j].pb(i); if (dp[j][0] > dp[j][1]){ for (int k = 0; k < n; k++){ vis[i][k][0] |= vis[j][k][0]; } }else{ for (int k = 0; k < n; k++){ vis[i][k][0] |= vis[j][k][1]; } } dp[i][0] += max(dp[j][1], dp[j][0]); for (int k = 0; k < n; k++){ vis[i][k][1] |= vis[j][k][0]; } a += dp[j][0]; } dp[i][1] = a+A[i]; if (vis[i][u[i]][1] == 0){ dp[i][1] += A[u[i]]; vis[i][u[i]][1] = 1; } } if (v[i] == 0 or v[i] == 2){ E[i].pb(u[i]); E[u[i]].pb(i); if (dp[u[i]][0] > dp[u[i]][1]){ for (int k = 0; k < n; k++){ vis[i][k][0] |= vis[u[i]][k][0]; } }else{ for (int k = 0; k < n; k++){ vis[i][k][0] |= vis[u[i]][k][1]; } } dp[i][0] = max(dp[u[i]][1], dp[u[i]][0]); for (int k = 0; k < n; k++){ vis[i][k][1] |= vis[u[i]][k][0]; } dp[i][1] = dp[u[i]][0]+A[i]; } } // if (!sub2) return max(dp[n-1][0], dp[n-1][1]); // if (!sub0 and !sub2) return sum; // if (!sub0 and !sub1) return *max_element(A, A+n); // if (!sub1 and !sub2){ // for (int i = 0; i < n; i++) dp[i][0] = dp[i][1] = 0; // dfs(0, -1, A); // return max(dp[0][1], dp[0][0]); // } // bit(0, n, A); // return mx; } // int main () // { // ios::sync_with_stdio(false); // cin.tie(0); // int n; // cin >> n; // int A[n], a[n], b[n]; // for (int i = 0; i < n; i++) cin >> A[i]; // for (int i = 1; i < n; i++) cin >> a[i] >> b[i]; // cout << findSample(n, A, a, b); // }

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:45:6: warning: variable 'sub0' set but not used [-Wunused-but-set-variable]
   45 |  int sub0 = 0, sub1 = 0, sub2 = 0;
      |      ^~~~
friend.cpp:45:16: warning: variable 'sub1' set but not used [-Wunused-but-set-variable]
   45 |  int sub0 = 0, sub1 = 0, sub2 = 0;
      |                ^~~~
friend.cpp:45:26: warning: variable 'sub2' set but not used [-Wunused-but-set-variable]
   45 |  int sub0 = 0, sub1 = 0, sub2 = 0;
      |                          ^~~~
#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...