#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
#include "roads.h"
long long dp[N][2];
int fr[N];
int to[N];
int w[N];
int n;
vector <long long> sub1() {
sort(w, w + (n - 1), greater <int>());
long long tot = accumulate(w, w + (n - 1), 0LL);
vector <long long> res;
res.push_back(tot);
for (int i = 0; i < n - 1; i++)
tot -= w[i], res.push_back(tot);
return res;
}
vector <long long> sub2() {
vector <long long> res;
res.push_back(accumulate(w, w + (n - 1), 0LL));
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
dp[i][j] = ooo;
dp[0][0] = 0;
for (int i = 1; i < n; i++) {
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + w[i - 1];
dp[i][1] = dp[i - 1][0];
}
res.push_back(min(dp[n - 1][0], dp[n - 1][1]));
for (int i = 2; i < n; i++)
res.push_back(0);
return res;
}
vector<long long> minimum_closure_costs(int N, vector<int> U,
vector<int> V,
vector<int> W) {
bool cond2 = true;
n = N;
for (int i = 0; i < n - 1; i++) {
fr[i] = U[i];
to[i] = V[i];
w[i] = W[i];
cond2 &= fr[i] == i && to[i] == i + 1;
}
if (*max_element(ALL(U)) == 0)
return sub1();
if (cond2)
return sub2();
return vector<long long>(N, 0);
}
//#include "grader.cpp"
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
24 ms |
3024 KB |
Output is correct |
13 |
Correct |
38 ms |
4936 KB |
Output is correct |
14 |
Correct |
44 ms |
4556 KB |
Output is correct |
15 |
Correct |
59 ms |
4920 KB |
Output is correct |
16 |
Correct |
55 ms |
4972 KB |
Output is correct |
17 |
Correct |
46 ms |
5040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
34 ms |
4580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
33 ms |
5652 KB |
Output is correct |
3 |
Correct |
41 ms |
8168 KB |
Output is correct |
4 |
Correct |
66 ms |
8604 KB |
Output is correct |
5 |
Correct |
44 ms |
8760 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
26 ms |
4712 KB |
Output is correct |
13 |
Correct |
41 ms |
7856 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
41 ms |
7216 KB |
Output is correct |
16 |
Correct |
38 ms |
7856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
24 ms |
3024 KB |
Output is correct |
13 |
Correct |
38 ms |
4936 KB |
Output is correct |
14 |
Correct |
44 ms |
4556 KB |
Output is correct |
15 |
Correct |
59 ms |
4920 KB |
Output is correct |
16 |
Correct |
55 ms |
4972 KB |
Output is correct |
17 |
Correct |
46 ms |
5040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
34 ms |
4580 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
33 ms |
5652 KB |
Output is correct |
22 |
Correct |
41 ms |
8168 KB |
Output is correct |
23 |
Correct |
66 ms |
8604 KB |
Output is correct |
24 |
Correct |
44 ms |
8760 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
444 KB |
Output is correct |
27 |
Correct |
1 ms |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
312 KB |
Output is correct |
30 |
Correct |
1 ms |
308 KB |
Output is correct |
31 |
Correct |
26 ms |
4712 KB |
Output is correct |
32 |
Correct |
41 ms |
7856 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
41 ms |
7216 KB |
Output is correct |
35 |
Correct |
38 ms |
7856 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |