답안 #955734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955734 2024-03-31T11:26:54 Z TimAni Burza (COCI16_burza) C++17
160 / 160
239 ms 1408 KB
//Bitmask DP Solution
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ms(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
//===========================================
const int MAX = 405;
vector<int> adj[MAX];
int dep[MAX], dp[1<<19], l[MAX], r[MAX], curr, n, k;

void dfs(int v, int p){
    if (dep[v] == k){ l[v] = r[v] = ++curr; return; }
    for (int u: adj[v]){
        if (u == p) continue;
        dep[u] = dep[v]+1;
        dfs(u, v);
        l[v] = min(l[v], l[u]);
        r[v] = max(r[v], r[u]);
    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    ms(l, INF); ms(r, 0);
    if (k * k >= n){ cout << "DA\n"; return 0; }
    for (int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1, -1);
    for (int mask = 1; mask < 1<<k; mask++){
        dp[mask] = -INF;
        for (int i = 1; i <= n; i++){
            if (!dep[i] || !(mask&(1<<(dep[i]-1)))) continue;
            if (dp[mask^(1<<(dep[i]-1))]+1 >= l[i]) dp[mask] = max({dp[mask], r[i], dp[mask^(1<<(dep[i]-1))]});
        }
    }
    cout << (dp[(1<<k)-1] == curr? "DA\n" : "NE\n");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 520 KB Output is correct
2 Correct 239 ms 1136 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 852 KB Output is correct
2 Correct 223 ms 920 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 231 ms 808 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 812 KB Output is correct
2 Correct 230 ms 1156 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 596 KB Output is correct
2 Correct 231 ms 852 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 860 KB Output is correct
2 Correct 231 ms 1328 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 480 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 800 KB Output is correct
2 Correct 222 ms 1224 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 852 KB Output is correct
2 Correct 222 ms 1408 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 218 ms 840 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 592 KB Output is correct
2 Correct 232 ms 896 KB Output is correct
3 Correct 0 ms 544 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 512 KB Output is correct
2 Correct 237 ms 1364 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 556 KB Output is correct
2 Correct 223 ms 848 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 98 ms 628 KB Output is correct
6 Correct 1 ms 348 KB Output is correct