Submission #105954

# Submission time Handle Problem Language Result Execution time Memory
105954 2019-04-15T20:43:10 Z nikolapesic2802 Burza (COCI16_burza) C++14
160 / 160
465 ms 54800 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

int n,k;
vector<vector<int> > dp,graf;
vector<vector<pair<int,int> > > nxt;
vector<int> in;
int t=0;
void init(int tr,int par,int d)
{
    in[tr]=t;
    if(d==k)
        t++;
    if(d!=k)
        for(auto p:graf[tr])
        {
            if(p==par)
                continue;
            init(p,tr,d+1);
        }
    if(t>in[tr]&&d!=0)
        nxt[in[tr]].pb({t,d-1});
}
bool calc(int mask,int tr)
{
    if(tr==t)
        return true;
    if(dp[mask][tr]!=-1)
        return dp[mask][tr];
    for(auto p:nxt[tr])
        if((mask&(1<<p.s))==0)
            if(calc(mask|(1<<p.s),p.f))
                return dp[mask][tr]=1;
    return dp[mask][tr]=0;
}
int main()
{
	scanf("%i %i",&n,&k);
	graf.resize(n);in.resize(n);nxt.resize(n);
	for(int i=1;i<n;i++)
    {
        int a,b;
        scanf("%i %i",&a,&b);
        a--;b--;
        graf[a].pb(b);
        graf[b].pb(a);
    }
    if(k*(k+1)+1>n)
    {
        printf("DA\n");
        return 0;
    }
    init(0,-1,0);
    dp.resize(1<<k,vector<int>(t+1,0));
    for(int i=0;i<1<<k;i++)
        dp[i][t]=1;
    for(int i=t-1;i>=0;i--)
    {
        for(int j=(1<<k)-1;j>=0;j--)
        {
            for(auto p:nxt[i])
            {
                if(((1<<p.s)&j)==0)
                    if(dp[j|(1<<p.s)][p.f])
                    {
                        dp[j][i]=1;
                        break;
                    }
            }
        }
    }
    if(dp[0][0])
        printf("DA\n");
    else
        printf("NE\n");
    return 0;
}

Compilation message

burza.cpp: In function 'bool calc(int, int)':
burza.cpp:56:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
                 return dp[mask][tr]=1;
burza.cpp:57:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     return dp[mask][tr]=0;
burza.cpp: In function 'int main()':
burza.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
burza.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7168 KB Output is correct
2 Correct 465 ms 52856 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 46604 KB Output is correct
2 Correct 398 ms 46488 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 370 ms 46584 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 46588 KB Output is correct
2 Correct 398 ms 46600 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 17536 KB Output is correct
2 Correct 395 ms 54800 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 40312 KB Output is correct
2 Correct 346 ms 44540 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 48720 KB Output is correct
2 Correct 455 ms 44636 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 442 ms 48640 KB Output is correct
2 Correct 346 ms 44536 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 344 ms 42368 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 13488 KB Output is correct
2 Correct 366 ms 50576 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5632 KB Output is correct
2 Correct 443 ms 50692 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 18400 KB Output is correct
2 Correct 366 ms 52748 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 119 ms 19376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct