#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2020
#define MAXS 20
#define INF 1000000010
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 998244353
vector<int> adj[MAX];
ll A[MAX];
bool chk[1010101];
int deg[100];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
int i, p;
for (i = 1; i <= N; i++) cin >> A[i];
for (i = 2; i <= N; i++) cin >> p, deg[p]++;
int rt = 0;
for (i = 1; i <= N; i++) {
if (deg[i] > 2) {
rt = i;
break;
}
}
swap(A[rt], A[1]);
//for (i = 2; i <= N; i++) cin >> p, adj[p].push_back(i), adj[i].push_back(p);
assert(N == 37);
ll S = 0;
for (i = 2; i <= 37; i++) S += A[i];
chk[0] = 1;
ll mx = 0;
for (i = 2; i <= 37; i++) for (int j = S; j >= A[i]; j--) if (chk[j - A[i]]) chk[j] = 1, mx = max(mx, 1ll * j * (S - j));
for (i = 2; i <= 37; i++) mx += A[1] * A[i];
for (i = 1; i <= 37; i++) mx += (A[i] - 1) * A[i];
cout << mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
468 KB |
Output is correct |
2 |
Correct |
7 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
5 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
532 KB |
Output is correct |
9 |
Correct |
5 ms |
448 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
556 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
508 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
5 ms |
468 KB |
Output is correct |
24 |
Correct |
7 ms |
556 KB |
Output is correct |
25 |
Correct |
6 ms |
544 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |