# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
516783 | 2022-01-22T06:15:45 Z | Be_dos | 바이오칩 (IZhO12_biochips) | C++17 | 2000 ms | 90540 KB |
#include <iostream> #include <cmath> #include <cctype> #include <vector> #include <algorithm> #include <set> #include <map> #include <deque> #include <stack> #include <unordered_set> #include <sstream> #include <cstring> #include <iomanip> #include <queue> #include <unordered_map> #include <random> #include <cfloat> #include <chrono> #include <bitset> #include <complex> #include <immintrin.h> #include <cassert> int32_t m; void dfs(int32_t v, std::vector<int32_t>* tree, int32_t** dp, int32_t* arr) { for(int32_t i = 0; i < tree[v].size(); i++) dfs(tree[v][i], tree, dp, arr); dp[v] = new int32_t[m + 1]; dp[v][0] = 0; for(int32_t i = 1; i <= m; i++) dp[v][i] = -1'000'000'000; int32_t* tmp = new int32_t[m + 1]; for(int32_t i = 0; i < tree[v].size(); i++) { for(int32_t j = 0; j <= m; j++) { tmp[j] = -1'000'000'000; for(int32_t k = 0; k <= j; k++) tmp[j] = std::max(tmp[j], dp[v][k] + dp[tree[v][i]][j - k]); } int32_t* tmp2 = dp[v]; dp[v] = tmp; tmp = tmp2; } dp[v][1] = std::max(dp[v][1], arr[v]); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int32_t n; std::cin >> n >> m; int32_t* arr = new int32_t[n]; std::vector<int32_t>* tree = new std::vector<int32_t>[n]; int32_t root = -1; for(int32_t i = 0; i < n; i++) { int32_t parent; std::cin >> parent >> arr[i]; parent--; if(parent == -1) root = i; else tree[parent].push_back(i); } int32_t** dp = new int32_t*[n]; dfs(root, tree, dp, arr); std::cout << dp[root][m]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 320 KB | Output is correct |
3 | Correct | 0 ms | 336 KB | Output is correct |
4 | Correct | 32 ms | 5192 KB | Output is correct |
5 | Correct | 44 ms | 7076 KB | Output is correct |
6 | Correct | 77 ms | 8952 KB | Output is correct |
7 | Execution timed out | 2025 ms | 90540 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |