답안 #144667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144667 2019-08-17T10:53:41 Z stefdasca Burza (COCI16_burza) C++14
160 / 160
77 ms 3320 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
vector<int>v[402], q[402];
int n, k, level[402], st[402], dr[402], pz;
void dfs(int dad, int nod)
{
    if(nod)
        level[nod] = level[dad] + 1;
    if(level[nod] == k-1)
    {
        st[nod] = pz++;
        dr[nod] = pz;
        return;
    }
    st[nod] = pz;
    for(int i = 0; i < v[nod].size(); ++i)
    {
        int vecin = v[nod][i];
        if(vecin == dad)
            continue;
        dfs(nod, vecin);
    }
    dr[nod] = pz;
}
bool dp[402][(1<<20)];
bool solve()
{
    dp[0][0] = 1;
    for(int i = 1; i < n; ++i)
        q[st[i]].push_back(i);

    for(int i = 0; i < pz; ++i)
    {
        for(int j = 0; j < (1<<k); ++j)
        {
            if (!dp[i][j])
                continue;
            for(int jj = 0; jj < q[i].size(); ++jj)
            {
                int it = q[i][jj];
                if (!(j >> level[it] & 1))
                    dp[dr[it]][j | (1<<level[it])] = 1;
            }
        }
    }
    for(int j = 0; j < (1<<k); ++j)
        if (dp[pz][j])
            return 1;

    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    if(k * k >= n)
    {
        cout << "DA\n";
        return 0;
    }
    for(int i = 1; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        v[a].pb(b);
        v[b].pb(a);
    }
    level[0] = -1;
    dfs(-1, 0);
    cout << (solve() ? "DA" : "NE");
    return 0;
}

Compilation message

burza.cpp: In function 'void dfs(int, int)':
burza.cpp:53:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[nod].size(); ++i)
                    ~~^~~~~~~~~~~~~~~
burza.cpp: In function 'bool solve()':
burza.cpp:75:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int jj = 0; jj < q[i].size(); ++jj)
                             ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1016 KB Output is correct
2 Correct 50 ms 2652 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 2720 KB Output is correct
2 Correct 52 ms 2680 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 77 ms 3064 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 2872 KB Output is correct
2 Correct 55 ms 2544 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1380 KB Output is correct
2 Correct 71 ms 3320 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2296 KB Output is correct
2 Correct 61 ms 3036 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 2752 KB Output is correct
2 Correct 60 ms 2808 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 3048 KB Output is correct
2 Correct 62 ms 2812 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 74 ms 3192 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1272 KB Output is correct
2 Correct 61 ms 2780 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 75 ms 2988 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1784 KB Output is correct
2 Correct 71 ms 3160 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 29 ms 1784 KB Output is correct
6 Correct 2 ms 632 KB Output is correct