답안 #297263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297263 2020-09-11T12:49:59 Z junseo 바이오칩 (IZhO12_biochips) C++17
100 / 100
562 ms 413432 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int maxn = 2e5 + 10;
const int maxm = 505;
 
int n, m, T = 0;
int p[maxn], t[maxn], d[maxn][maxm];
vector<int> root, adj[maxn];
vector<pii> v[maxn];
 
inline void rmax(int& r, int x) { r = max(r, x); }
 
void dfs(int u) {
    int in = ++T;
    for(auto v : adj[u])    dfs(v);
    int out = T;
    v[out].eb(in, t[u]);
}
 
int main(void) {
    fastio;
    cin >> n >> m;
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> p[i] >> t[i];
        if(!p[i])   root.eb(i);
        else        adj[p[i]].eb(i);
    }
    // assert(root.size() == 1);
    for(auto& r : root) dfs(r);
    for(int i = 1; i <= m; ++i) d[0][i] = INT_MIN;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j <= m; ++j) d[i][j] = d[i - 1][j];
        for(int j = 1; j <= m; ++j) {
            for(auto [l, w] : v[i]) rmax(d[i][j], d[l - 1][j - 1] + w);
        }
    }
    cout << d[n][m];
    return 0;
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:34:9: warning: unused variable 'cnt' [-Wunused-variable]
   34 |     int cnt = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9984 KB Output is correct
4 Correct 22 ms 27776 KB Output is correct
5 Correct 24 ms 30080 KB Output is correct
6 Correct 24 ms 30080 KB Output is correct
7 Correct 350 ms 309496 KB Output is correct
8 Correct 345 ms 309496 KB Output is correct
9 Correct 462 ms 374904 KB Output is correct
10 Correct 562 ms 413432 KB Output is correct