Submission #2489923


Source Code Expand

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,vector<lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;
 
lli n;
unordered_map<lli,lli> x;
graph t;
vll dp,dq;
 
bool check(lli b,lli c){
  if(b&c) return false;
  for(lli d : t[c]){
    if((b&d) == 0) return false;
  }
  return true;
}
 
int main(){
  cin >> n;
  lli ub = 1ll << n;
  for(lli i = 1ll;i < ub;i <<= 1) cin >> x[i];
  for(lli i = 2ll;i < ub;i <<= 1){
    lli a;
    cin >> a;
    t[1ll << (a-1)].push_back(i);
  }
  dp = vll(ub,INT_MAX);
  dq = vll(ub,INT_MAX);
  dp[0] = 0;
  dq[0] = 0;
  for(lli b = 0;b < ub;b++){
    for(lli c = 1ll;c < ub;c <<= 1){
      if(check(b,c)){
        lli y = dp[b]+x[c];
        dq[b|c] = min(dq[b|c],max(dq[b],y));
        for(lli z : t[c]) y -= x[z];
        dp[b|c] = min(dp[b|c],y);
      }
    }
  }
  cout << dq[ub-1] << endl;
  return 0;
}

Submission Info

Submission Time
Task D - ディスクの節約
User luogu_bot5
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1121 Byte
Status AC
Exec Time 632 ms
Memory 16768 KB

Judge Result

Set Name All
Score / Max Score 600 / 600
Status
AC × 57
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 AC 1 ms 256 KB
10_complete00 AC 540 ms 16768 KB
10_complete01 AC 1 ms 256 KB
10_complete02 AC 1 ms 256 KB
10_complete03 AC 2 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 631 ms 16640 KB
21_urchin-large01 AC 632 ms 16640 KB
21_urchin-large02 AC 632 ms 16640 KB
21_urchin-large03 AC 632 ms 16640 KB
21_urchin-large04 AC 632 ms 16640 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 550 ms 16640 KB
31_random-large01 AC 556 ms 16640 KB
31_random-large02 AC 570 ms 16640 KB
31_random-large03 AC 568 ms 16640 KB
31_random-large04 AC 561 ms 16640 KB
40_boundary00 AC 1 ms 256 KB
40_boundary01 AC 631 ms 16640 KB