제출 #613815

#제출 시각아이디문제언어결과실행 시간메모리
613815AugustinasJucas도로 폐쇄 (APIO21_roads)C++14
12 / 100
91 ms19284 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; const int dydis = 1e5 + 10; vector<pair<int, int> > gr[dydis]; const long long inf = 1e14 + 1; int n, m; vector<int> mas; auto lin() { /// Galiu praleisti max 1 is eiles. Kokia min suma? long long dp[n]; /// dp[i] - turiu visus iki i ir i-aji emiau. Kokia min suma? dp[0] = mas[0]; dp[1] = mas[1]; for(int i = 2; i < n; i++) { dp[i] = min(dp[i-1] + mas[i], dp[i-2] + mas[i]); } vector<long long> ret(n, 0); for(auto x : mas) ret[0] += x; ret[1] = min(dp[n-1], dp[n-2]); return ret; } auto starr() { //cout << "star - " << true << endl; sort(mas.begin(), mas.end()); reverse(mas.begin(), mas.end()); vector<long long> ret(n, 0); for(auto x : mas) ret[0] += x; long long sum = 0; for(int i = n-1; i > 0; i--) { if(i != n- 1) sum += mas[i]; ret[i] = sum; } return ret; } long long dp[2100][2100][2]; /// dp[v][k][isimuVirsu] void dfs(int v, int came, int wUp, int k) { vector<long long> pos; for(auto x : gr[v]) { if(x.first == came) continue; dfs(x.first, v, x.second, k); pos.push_back(dp[x.first][k][1]); } sort(pos.begin(), pos.end()); int reikIsimt = 0; if(k == 0) { /// turiu paimti viska!!! long long sm = wUp; for(auto x : gr[v]) { if(x.first == came) continue; sm += dp[x.first][k][1]; } dp[v][k][1] = sm; dp[v][k][0] = inf; if(v == 0) dp[v][k][0] = sm; return ; } /// dp[v][k][0] - jei neimu virsaus reikIsimt = max(0, (int)gr[v].size() - k); long long sum = 0; vector<long long> vec; for(auto x : gr[v]) { if(x.first == came) continue; sum += dp[x.first][k][0]; /// pridedu kas bus jei neerasinsiu vec.push_back(-dp[x.first][k][0] + dp[x.first][k][1]); } sort(vec.begin(), vec.end()); dp[v][k][0] = sum; for(int i = 0; i < reikIsimt; i++) { dp[v][k][0] += vec[i]; } for(int i = reikIsimt; i < vec.size(); i++) if(vec[i] < 0) dp[v][k][0] += vec[i]; dp[v][k][1] = sum + wUp; reikIsimt = max(0, (int)gr[v].size() - k - 1); for(int i = 0; i < reikIsimt; i++) { dp[v][k][1] += vec[i]; } for(int i = reikIsimt; i < vec.size(); i++) if(vec[i] < 0) dp[v][k][0] += vec[i]; } vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; m = W.size(); bool line = true, star = true; for(int i = 0; i < m; i++) { int a = U[i]; int b = V[i]; int w = W[i]; if(a != b-1) line = false; if(a != 0) star = false; gr[a].push_back({b, w}); gr[b].push_back({a, w}); mas.push_back(w); } if(line) { return lin(); } if(star) { return starr(); } vector<long long> ret(n, 0); for(int i = 0; i < n; i++) { dfs(0, 0, 0, i); ret[i] = dp[0][i][0]; } return ret; }

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

roads.cpp: In function 'void dfs(int, int, int, int)':
roads.cpp:78:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i = reikIsimt; i < vec.size(); i++) if(vec[i] < 0) dp[v][k][0] += vec[i];
      |                            ~~^~~~~~~~~~~~
roads.cpp:86:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int i = reikIsimt; i < vec.size(); i++) if(vec[i] < 0) dp[v][k][0] += vec[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...
#Verdict Execution timeMemoryGrader output
Fetching results...