제출 #1083578

#제출 시각아이디문제언어결과실행 시간메모리
1083578raczekJobs (BOI24_jobs)C++17
0 / 100
566 ms486496 KiB
#include<bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";} auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";} #define debug(X) cout<<"["#X"]"<<X<<endl; #else #define debug(X) {} #endif const long long INF = numeric_limits<long long>::max(); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, s; cin>>n>>s; vector<vector<int> > graph(n+1); vector<long long> cost(n+1); for(int i=1;i<=n;i++) { long long c, p; cin>>c>>p; graph[p].push_back(i); cost[i] = c; } vector<vector<pair<int, long long> > > pool(n+1); function<void(int)> dfs = [&](int b){ priority_queue<pair<long long, int> > q; for(auto v : graph[b]) {dfs(v); q.push({pool[v].back().second, v});}; vector<pair<int, long long> > myP = {{cost[b], 0}}; if(graph[b].size() == 1) { pool[b] = pool[graph[b][0]]; long long c = 0; if(cost[b] < 0) c = pool[b].back().second + cost[b]; if(pool[b].back().second == -INF && cost[b] < 0) c = -INF; pool[b].push_back({cost[b], c}); debug(pool[b]); return; } while(!q.empty()) { auto a = q.top().second; q.pop(); myP.push_back({pool[a].back().first, 0}); pool[a].pop_back(); if(pool[a].size() > 0) q.push({pool[a].back().second, a}); } long long checkP = -1, akt = 0; for(int i=0;i<myP.size();i++) { akt += myP[i].first; if(akt >= 0) { akt -= myP[i].first; for(int j=checkP+1;j<=i;j++) { myP[j].second = akt; if(myP[j].first >= 0) myP[j].second = 0; akt -= myP[j].first; } checkP = i; akt = 0; } } for(int i=checkP+1;i<myP.size();i++) if(myP[i].first < 0) myP[i].second = -INF; reverse(myP.begin(), myP.end()); debug(b); debug(myP); pool[b] = myP; }; dfs(0); long long org = s; while(pool[0].size()) { debug(pool[0].back()); if(pool[0].back().second + s < 0) break; if(s + pool[0].back().first >= 0) {s += pool[0].back().first; pool[0].pop_back();} } cout<<s - org; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In lambda function:
Main.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int i=0;i<myP.size();i++)
      |               ~^~~~~~~~~~~
Main.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int i=checkP+1;i<myP.size();i++) if(myP[i].first < 0) myP[i].second = -INF;
      |                      ~^~~~~~~~~~~
#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...