답안 #1023876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023876 2024-07-15T08:24:30 Z caterpillow Burza (COCI16_burza) C++17
0 / 160
116 ms 250988 KB
#include <bits/stdc++.h>
#include <random>
 
using namespace std;
 
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
 
int n, k, t;
vt<vt<int>> adj;
vt<int> depth, pos, jump, val, rpos;
 
void dfs(int u, int p = -1) {
    pos[u] = t++;
    if (depth[u] == k) val[u] = 1;
    for (int v : adj[u]) {
        if (v == p) continue;
        depth[v] = depth[u] + 1;
        dfs(v, u);
        val[u] += val[v];
    }
    jump[u] = t;
}
 
int memo[400][400][400];
 
int dp(int i, int l, int r) {
    if (i == n) return 0;
    if (l > r) return 0;
    if (memo[i][l][r] != -1) return memo[i][l][r];
    int u = rpos[i]; // get the actual node index at this position
 
    int ans = 0;
    if (l <= depth[u] && depth[u] <= r) { // allowed to take yourself
        ans = val[u] + dp(jump[u], l, depth[u] - 1) + dp(jump[u], depth[u] + 1, r);
    }
    ans = max(ans, dp(i + 1, l, r));
    
    return memo[i][l][r] = ans;
}
 
main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> k;
    adj.resize(n);
    depth = pos = jump = val = rpos = vt<int>(n, 0);
    F0R (i, n - 1) {
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
 
    dfs(0);
    F0R (i, n) rpos[pos[i]] = i;
    memset(memo, -1, sizeof(memo));
 
    if (dp(0, 1, k) == val[0]) cout << "DA\n";
    else cout << "NE\n";
}

Compilation message

burza.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 250960 KB Output is correct
2 Correct 109 ms 250988 KB Output is correct
3 Incorrect 113 ms 250964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 250960 KB Output is correct
2 Correct 105 ms 250892 KB Output is correct
3 Incorrect 105 ms 250960 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 250964 KB Output is correct
2 Correct 114 ms 250960 KB Output is correct
3 Incorrect 104 ms 250964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 250964 KB Output is correct
2 Correct 106 ms 250960 KB Output is correct
3 Incorrect 106 ms 250960 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 250772 KB Output is correct
2 Correct 115 ms 250736 KB Output is correct
3 Incorrect 108 ms 250784 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 250960 KB Output is correct
2 Correct 108 ms 250972 KB Output is correct
3 Incorrect 106 ms 250856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 250964 KB Output is correct
2 Correct 107 ms 250960 KB Output is correct
3 Incorrect 106 ms 250964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 250964 KB Output is correct
2 Correct 115 ms 250968 KB Output is correct
3 Incorrect 111 ms 250848 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 250960 KB Output is correct
2 Correct 116 ms 250892 KB Output is correct
3 Incorrect 108 ms 250964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 250820 KB Output is correct
2 Correct 107 ms 250960 KB Output is correct
3 Incorrect 102 ms 250964 KB Output isn't correct
4 Halted 0 ms 0 KB -