답안 #1024079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024079 2024-07-15T11:29:42 Z caterpillow Burza (COCI16_burza) C++17
144 / 160
569 ms 410876 KB
#include <bits/stdc++.h>
 
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;

#define char unsigned char

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
int n, k, t;
vt<vt<int>> adj;
vt<int> depth, pos, jump, rpos;
vt<char> val;
 
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;
}
 
const int mxk = 20;
char dp[401][1 << mxk];
 
main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> k;
    if (k * k >= n) {
        cout << "DA\n";
        return 0;
    }
    adj.resize(n);
    depth = pos = jump = rpos = vt<int>(n, 0);
    val.resize(n);
    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;

    ROF (i, 0, n) {
        int u = rpos[i];
        F0R (msk, 1 << mxk) { 
            dp[i][msk] = dp[i + 1][msk];
            if (depth[u] <= k && (1 & (msk >> depth[u]))) dp[i][msk] = max(dp[i][msk], (char) (val[u] + dp[jump[u]][msk ^ (1 << depth[u])]));
        }   
    }

    if (dp[0][(1 << mxk) - 2] == val[0]) cout << "DA\n";
    else cout << "NE\n";
}

Compilation message

burza.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 320592 KB Output is correct
2 Correct 494 ms 410644 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 538 ms 393312 KB Output is correct
6 Correct 107 ms 93780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 390224 KB Output is correct
2 Correct 472 ms 392276 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 532 ms 397496 KB Output is correct
6 Incorrect 487 ms 406604 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 503 ms 395348 KB Output is correct
2 Correct 479 ms 395344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 394 ms 318288 KB Output is correct
6 Correct 116 ms 100948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 386144 KB Output is correct
2 Correct 521 ms 410876 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 321 ms 273216 KB Output is correct
6 Correct 94 ms 83540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 377936 KB Output is correct
2 Correct 489 ms 390520 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 467 ms 394348 KB Output is correct
6 Correct 327 ms 278504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 393288 KB Output is correct
2 Correct 481 ms 387160 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 465 ms 364688 KB Output is correct
6 Correct 286 ms 245584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 569 ms 400392 KB Output is correct
2 Correct 475 ms 389204 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 491 ms 390228 KB Output is correct
6 Correct 374 ms 322384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 434 ms 345104 KB Output is correct
2 Correct 477 ms 402508 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 295 ms 245560 KB Output is correct
6 Correct 493 ms 400744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 286568 KB Output is correct
2 Correct 519 ms 406596 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 282 ms 247676 KB Output is correct
6 Correct 436 ms 368724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 412 ms 341088 KB Output is correct
2 Correct 563 ms 405584 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 439 ms 345012 KB Output is correct
6 Correct 196 ms 175696 KB Output is correct