Submission #101594

# Submission time Handle Problem Language Result Execution time Memory
101594 2019-03-19T04:49:40 Z jamielim Chase (CEOI17_chase) C++14
70 / 100
2154 ms 93560 KB
#include <bits/stdc++.h>
using namespace std;

int n,v;
vector<int> adj[100005];
long long arr[100005];
long long pigeons[100005];
long long memo[100005][105];
long long dp(int x,int vleft,int p){
    if(memo[x][vleft]!=-1)return memo[x][vleft];
    if(vleft==0)return memo[x][0]=0;
    if(adj[x].size()==0)return memo[x][vleft]=pigeons[x]-(p==-1?0:arr[p]);
    long long ans=0;
    for(int i=0;i<(int)adj[x].size();i++){
        if(adj[x][i]==p)continue;
        ans=max(ans,max(dp(adj[x][i],vleft,x),dp(adj[x][i],vleft-1,x)+pigeons[x]-(p==-1?0:arr[p])));
    }
    return memo[x][vleft]=ans;
}

int main(){
    scanf("%d%d",&n,&v);
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    int a,b;
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&a,&b); a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        pigeons[i]=0;
        for(int j=0;j<(int)adj[i].size();j++){
            pigeons[i]+=arr[adj[i][j]];
        }
    }
    if(n<=1000){
        long long ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<=v;k++){
                    memo[j][k]=-1;
                }
            }
            ans=max(ans,dp(i,v,-1));
        }
        printf("%lld",ans);
        return 0;
    }
    memset(memo,-1,sizeof(memo));
    long long ans=dp(0,v,-1);
    for(int i=0;i<5000000/n/v;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<=v;k++){
                memo[j][k]=-1;
            }
        }
        ans=max(ans,dp(rand()%n,v,-1));
    }
    printf("%lld",ans);
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:24:27: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d",&arr[i]);
                    ~~~~~~~^
chase.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&v);
     ~~~~~^~~~~~~~~~~~~~
chase.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&arr[i]);
         ~~~~~^~~~~~~~~~~~~~
chase.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b); a--; b--;
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 1580 ms 3624 KB Output is correct
8 Correct 104 ms 3676 KB Output is correct
9 Correct 38 ms 3584 KB Output is correct
10 Correct 283 ms 3584 KB Output is correct
11 Correct 227 ms 3584 KB Output is correct
12 Correct 194 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2154 ms 93560 KB Output is correct
2 Correct 1968 ms 93532 KB Output is correct
3 Correct 173 ms 89968 KB Output is correct
4 Correct 1535 ms 89768 KB Output is correct
5 Correct 817 ms 89616 KB Output is correct
6 Correct 631 ms 89612 KB Output is correct
7 Correct 883 ms 89720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 1580 ms 3624 KB Output is correct
8 Correct 104 ms 3676 KB Output is correct
9 Correct 38 ms 3584 KB Output is correct
10 Correct 283 ms 3584 KB Output is correct
11 Correct 227 ms 3584 KB Output is correct
12 Correct 194 ms 3584 KB Output is correct
13 Correct 2154 ms 93560 KB Output is correct
14 Correct 1968 ms 93532 KB Output is correct
15 Correct 173 ms 89968 KB Output is correct
16 Correct 1535 ms 89768 KB Output is correct
17 Correct 817 ms 89616 KB Output is correct
18 Correct 631 ms 89612 KB Output is correct
19 Correct 883 ms 89720 KB Output is correct
20 Incorrect 331 ms 89784 KB Output isn't correct
21 Halted 0 ms 0 KB -