Submission #2121839


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

vector<int> children[20], cost(20, 0);
vector<int> x(20);

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    rep(n) cin >> x[i];
    reppp(i, 1, n){
        int tmp;
        cin >> tmp;
        children[tmp-1].push_back(i);
    }
    

    for(int i=n-1;i>=0;i--){
        if(children[i].empty()){
            cost[i] = x[i];
        }else{
            sort(all(children[i]), [&](int a, int b){
                return cost[a]-x[a] > cost[b]-x[b];
            });
            int tmp = 0, tmpans = 0;
            for(int c: children[i]){
                tmpans = max(tmpans, tmp+cost[c]);
                tmp += x[c];
            }
            cost[i] = max(tmpans, tmp+x[i]);
        }
    }

    cout << *max_element(all(cost)) << endl;
}

Submission Info

Submission Time
Task D - ディスクの節約
User Noimin
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1447 Byte
Status WA
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 0 / 600
Status
AC × 56
WA × 1
Set Name Test Cases
All 00_sample01, 00_sample02, 00_sample03, 01_handmade00, 01_handmade01, 02_tayama_killer00, 10_complete00, 10_complete01, 10_complete02, 10_complete03, 20_urchin-small00, 20_urchin-small01, 20_urchin-small02, 20_urchin-small03, 20_urchin-small04, 21_urchin-large00, 21_urchin-large01, 21_urchin-large02, 21_urchin-large03, 21_urchin-large04, 30_random-small00, 30_random-small01, 30_random-small02, 30_random-small03, 30_random-small04, 30_random-small05, 30_random-small06, 30_random-small07, 30_random-small08, 30_random-small09, 30_random-small10, 30_random-small11, 30_random-small12, 30_random-small13, 30_random-small14, 30_random-small15, 30_random-small16, 30_random-small17, 30_random-small18, 30_random-small19, 30_random-small20, 30_random-small21, 30_random-small22, 30_random-small23, 30_random-small24, 30_random-small25, 30_random-small26, 30_random-small27, 30_random-small28, 30_random-small29, 31_random-large00, 31_random-large01, 31_random-large02, 31_random-large03, 31_random-large04, 40_boundary00, 40_boundary01
Case Name Status Exec Time Memory
00_sample01 AC 1 ms 256 KB
00_sample02 AC 1 ms 256 KB
00_sample03 AC 1 ms 256 KB
01_handmade00 AC 1 ms 256 KB
01_handmade01 AC 1 ms 256 KB
02_tayama_killer00 WA 1 ms 256 KB
10_complete00 AC 1 ms 256 KB
10_complete01 AC 1 ms 256 KB
10_complete02 AC 1 ms 256 KB
10_complete03 AC 1 ms 256 KB
20_urchin-small00 AC 1 ms 256 KB
20_urchin-small01 AC 1 ms 256 KB
20_urchin-small02 AC 1 ms 256 KB
20_urchin-small03 AC 1 ms 256 KB
20_urchin-small04 AC 1 ms 256 KB
21_urchin-large00 AC 1 ms 256 KB
21_urchin-large01 AC 1 ms 256 KB
21_urchin-large02 AC 1 ms 256 KB
21_urchin-large03 AC 1 ms 256 KB
21_urchin-large04 AC 1 ms 256 KB
30_random-small00 AC 1 ms 256 KB
30_random-small01 AC 1 ms 256 KB
30_random-small02 AC 1 ms 256 KB
30_random-small03 AC 1 ms 256 KB
30_random-small04 AC 1 ms 256 KB
30_random-small05 AC 1 ms 256 KB
30_random-small06 AC 1 ms 256 KB
30_random-small07 AC 1 ms 256 KB
30_random-small08 AC 1 ms 256 KB
30_random-small09 AC 1 ms 256 KB
30_random-small10 AC 1 ms 256 KB
30_random-small11 AC 1 ms 256 KB
30_random-small12 AC 1 ms 256 KB
30_random-small13 AC 1 ms 256 KB
30_random-small14 AC 1 ms 256 KB
30_random-small15 AC 1 ms 256 KB
30_random-small16 AC 1 ms 256 KB
30_random-small17 AC 1 ms 256 KB
30_random-small18 AC 1 ms 256 KB
30_random-small19 AC 1 ms 256 KB
30_random-small20 AC 1 ms 256 KB
30_random-small21 AC 1 ms 256 KB
30_random-small22 AC 1 ms 256 KB
30_random-small23 AC 1 ms 256 KB
30_random-small24 AC 1 ms 256 KB
30_random-small25 AC 1 ms 256 KB
30_random-small26 AC 1 ms 256 KB
30_random-small27 AC 1 ms 256 KB
30_random-small28 AC 1 ms 256 KB
30_random-small29 AC 1 ms 256 KB
31_random-large00 AC 1 ms 256 KB
31_random-large01 AC 1 ms 256 KB
31_random-large02 AC 1 ms 256 KB
31_random-large03 AC 1 ms 256 KB
31_random-large04 AC 1 ms 256 KB
40_boundary00 AC 1 ms 256 KB
40_boundary01 AC 1 ms 256 KB