Submission #986414

#TimeUsernameProblemLanguageResultExecution timeMemory
986414Neco_arcCat in a tree (BOI17_catinatree)C++17
51 / 100
1032 ms154040 KiB
#include <bits/stdc++.h> //#include <bits/debug.hpp> #define ll long long #define all(x) x.begin(), x.end() #define Neco "Maximum Weight Subset" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 2e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; int n, k; vector<int> edges[maxn]; deque<int> dp[maxn]; deque<int> cb(const deque<int> &a, const deque<int> &b) { deque<int> ans(a.size() + b.size() - 1, -1e9); fi(i, 0, a.size() - 1) fi(j, 0, b.size() - 1) { if(i + j >= k) ans[min(i, j)] = max(ans[min(i, j)], a[i] + b[j]); } fi(i, 0, b.size() - 1) ans[i] = max(ans[i], b[i]); fi(i, 0, a.size() - 1) ans[i] = max(ans[i], a[i]); return ans; } void dfs(int u, int par) { dp[u] = {1}; for(int v : edges[u]) if(v != par) { dfs(v, u); dp[u] = cb(dp[u], dp[v]); } dp[u].push_front(-1e9); } void solve() { cin >> n >> k; fi(i, 2, n) { int x; cin >> x, ++x; edges[x].push_back(i); } dfs(1, 0); cout << *max_element(all(dp[1])); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'std::deque<int> cb(const std::deque<int>&, const std::deque<int>&)':
catinatree.cpp:12:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
   27 |     fi(i, 0, a.size() - 1) fi(j, 0, b.size() - 1) {
      |        ~~~~~~~~~~~~~~~~~~             
catinatree.cpp:27:5: note: in expansion of macro 'fi'
   27 |     fi(i, 0, a.size() - 1) fi(j, 0, b.size() - 1) {
      |     ^~
catinatree.cpp:12:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
   27 |     fi(i, 0, a.size() - 1) fi(j, 0, b.size() - 1) {
      |                               ~~~~~~~~~~~~~~~~~~
catinatree.cpp:27:28: note: in expansion of macro 'fi'
   27 |     fi(i, 0, a.size() - 1) fi(j, 0, b.size() - 1) {
      |                            ^~
catinatree.cpp:12:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
   30 |     fi(i, 0, b.size() - 1) ans[i] = max(ans[i], b[i]);
      |        ~~~~~~~~~~~~~~~~~~             
catinatree.cpp:30:5: note: in expansion of macro 'fi'
   30 |     fi(i, 0, b.size() - 1) ans[i] = max(ans[i], b[i]);
      |     ^~
catinatree.cpp:12:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
   31 |     fi(i, 0, a.size() - 1) ans[i] = max(ans[i], a[i]);
      |        ~~~~~~~~~~~~~~~~~~             
catinatree.cpp:31:5: note: in expansion of macro 'fi'
   31 |     fi(i, 0, a.size() - 1) ans[i] = max(ans[i], a[i]);
      |     ^~
catinatree.cpp: In function 'int main()':
catinatree.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
catinatree.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...