# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101594 | 2019-03-19T04:49:40 Z | jamielim | Chase (CEOI17_chase) | C++14 | 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
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | - |