Contest Duration: ~ (local time) (100 minutes) Back to Home

Submission #2780732

Source Code Expand

Copy
```#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

pll top2(pll x, pll y) {
vector<ll> s = { x.first, x.second, y.first, y.second };
sort(s.begin(), s.end(), greater<ll>());
return pll(s[0], s[1]);
}

int main(void) {
ll N;
cin >> N;
vector<ll> A(1LL << N);
REP(i, 0, 1LL << N) cin >> A[i];

const ll INF = 1LL << 50;
vector<pll> dp(1LL << N);
REP(i, 0, 1LL << N) dp[i] = pll(i, 0);
REP(i, 0, 1LL << N) {
REP(j, 0, N) if(!(i & (1LL << j))) {
pll x = dp[i | (1LL << j)], y = dp[i];
vector<ll> s = { x.first, x.second, y.first, y.second };
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
sort(s.begin(), s.end(), [&](ll p, ll q) { return A[p] > A[q]; });
dp[i | (1LL << j)] = pll(s[0], s[1]);
}
}

ll ans = 0;
REP(i, 1, 1LL << N) {
ans = max(ans, A[dp[i].first] + A[dp[i].second]);
cout << ans << endl;
}
}```

#### Submission Info

Submission Time 2018-07-02 11:55:39+0900 E - Or Plus Max kshinya C++14 (GCC 5.4.1) 700 1052 Byte AC 718 ms 10624 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB