# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671137 | 2022-12-12T07:23:46 Z | vuavisao | Feast (NOI19_feast) | C++14 | 126 ms | 10412 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long using namespace std; template<typename Lhs, typename Rhs> inline bool Max_self(Lhs &a, Rhs b) { if(b > a) { a = b; return true; } return false; } template<typename Lhs, typename Rhs> inline bool Min_self(Lhs &a, Rhs b) { if(b < a) { a = b; return true; } return false; } const ll N = 3e5 + 10; const ll INF = 1e18; ll n, k, a[N]; namespace sub6 { bool check() { return (n <= 2000); } ll dp[2010][2010]; ll res; void solve() { for(ll gr = 1; gr <= k; ++ gr) { for(ll i = 1; i <= n; ++ i) { Max_self(dp[i][gr], dp[i - 1][gr] + a[i]); Max_self(dp[i][gr], dp[i - 1][gr - 1] + a[i]); } for(ll i = 1; i <= n; ++ i) Max_self(dp[i][gr], dp[i - 1][gr]); Max_self(res, dp[n][gr]); } cout << res; } } namespace last_sub { ll dp[N], cnt[N]; bool check(ll lamba) { ll best[2] = {0, 0}; for(ll i = 1; i <= n; ++ i) { dp[i] = dp[i - 1]; cnt[i] = cnt[i - 1]; if(Max_self(dp[i], best[0] + a[i] - lamba)) { cnt[i] = cnt[best[1]] + 1; } if(Max_self(best[0], dp[i] - a[i])) { best[1] = i; } } return (cnt[n] <= k); } void solve() { // cout << check(INF) << '\n'; for(ll i = 1; i <= n; ++ i) a[i] += a[i - 1]; ll l = 0, r = INF; ll lamba = - 1; while(l <= r) { ll mid = (l + r) >> 1ll; if(check(mid)) { lamba = mid; r = mid - 1; } else l = mid + 1; } assert(lamba != - 1); check(lamba); // cout << dp[n] << ' ' << cnt[n] << '\n'; cout << dp[n] + lamba * cnt[n]; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("Feast.inp", "r")) { freopen("Feast.inp", "r", stdin); freopen("Feast.out", "w", stdout); } cin >> n >> k; for(ll i = 1; i <= n; ++ i) cin >> a[i]; // if(sub6::check()) { // sub6::solve(); // return 0; // } // assert(false); last_sub::solve(); return 0; } /// Code by vuavisao
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 7756 KB | Output is correct |
2 | Correct | 65 ms | 10236 KB | Output is correct |
3 | Correct | 67 ms | 10212 KB | Output is correct |
4 | Correct | 62 ms | 10060 KB | Output is correct |
5 | Correct | 62 ms | 10048 KB | Output is correct |
6 | Correct | 66 ms | 9888 KB | Output is correct |
7 | Correct | 63 ms | 10000 KB | Output is correct |
8 | Correct | 61 ms | 10112 KB | Output is correct |
9 | Correct | 60 ms | 9968 KB | Output is correct |
10 | Correct | 64 ms | 10020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 7748 KB | Output is correct |
2 | Correct | 59 ms | 8364 KB | Output is correct |
3 | Correct | 60 ms | 8352 KB | Output is correct |
4 | Correct | 54 ms | 8352 KB | Output is correct |
5 | Correct | 61 ms | 9924 KB | Output is correct |
6 | Correct | 56 ms | 8344 KB | Output is correct |
7 | Correct | 55 ms | 8484 KB | Output is correct |
8 | Correct | 61 ms | 10108 KB | Output is correct |
9 | Correct | 61 ms | 9976 KB | Output is correct |
10 | Correct | 54 ms | 8396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 88 ms | 7824 KB | Output is correct |
2 | Correct | 89 ms | 10176 KB | Output is correct |
3 | Correct | 88 ms | 10188 KB | Output is correct |
4 | Correct | 97 ms | 10176 KB | Output is correct |
5 | Correct | 87 ms | 10236 KB | Output is correct |
6 | Correct | 101 ms | 10316 KB | Output is correct |
7 | Correct | 89 ms | 10372 KB | Output is correct |
8 | Correct | 89 ms | 10248 KB | Output is correct |
9 | Correct | 92 ms | 10396 KB | Output is correct |
10 | Correct | 89 ms | 10324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 324 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 344 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 336 KB | Output is correct |
28 | Correct | 1 ms | 344 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 7756 KB | Output is correct |
2 | Correct | 65 ms | 10236 KB | Output is correct |
3 | Correct | 67 ms | 10212 KB | Output is correct |
4 | Correct | 62 ms | 10060 KB | Output is correct |
5 | Correct | 62 ms | 10048 KB | Output is correct |
6 | Correct | 66 ms | 9888 KB | Output is correct |
7 | Correct | 63 ms | 10000 KB | Output is correct |
8 | Correct | 61 ms | 10112 KB | Output is correct |
9 | Correct | 60 ms | 9968 KB | Output is correct |
10 | Correct | 64 ms | 10020 KB | Output is correct |
11 | Correct | 60 ms | 7748 KB | Output is correct |
12 | Correct | 59 ms | 8364 KB | Output is correct |
13 | Correct | 60 ms | 8352 KB | Output is correct |
14 | Correct | 54 ms | 8352 KB | Output is correct |
15 | Correct | 61 ms | 9924 KB | Output is correct |
16 | Correct | 56 ms | 8344 KB | Output is correct |
17 | Correct | 55 ms | 8484 KB | Output is correct |
18 | Correct | 61 ms | 10108 KB | Output is correct |
19 | Correct | 61 ms | 9976 KB | Output is correct |
20 | Correct | 54 ms | 8396 KB | Output is correct |
21 | Correct | 88 ms | 7824 KB | Output is correct |
22 | Correct | 89 ms | 10176 KB | Output is correct |
23 | Correct | 88 ms | 10188 KB | Output is correct |
24 | Correct | 97 ms | 10176 KB | Output is correct |
25 | Correct | 87 ms | 10236 KB | Output is correct |
26 | Correct | 101 ms | 10316 KB | Output is correct |
27 | Correct | 89 ms | 10372 KB | Output is correct |
28 | Correct | 89 ms | 10248 KB | Output is correct |
29 | Correct | 92 ms | 10396 KB | Output is correct |
30 | Correct | 89 ms | 10324 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 0 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 340 KB | Output is correct |
35 | Correct | 0 ms | 340 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 1 ms | 340 KB | Output is correct |
38 | Correct | 0 ms | 340 KB | Output is correct |
39 | Correct | 0 ms | 340 KB | Output is correct |
40 | Correct | 1 ms | 340 KB | Output is correct |
41 | Correct | 1 ms | 340 KB | Output is correct |
42 | Correct | 0 ms | 340 KB | Output is correct |
43 | Correct | 0 ms | 340 KB | Output is correct |
44 | Correct | 1 ms | 340 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 1 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 340 KB | Output is correct |
48 | Correct | 1 ms | 332 KB | Output is correct |
49 | Correct | 1 ms | 340 KB | Output is correct |
50 | Correct | 1 ms | 324 KB | Output is correct |
51 | Correct | 1 ms | 340 KB | Output is correct |
52 | Correct | 1 ms | 344 KB | Output is correct |
53 | Correct | 1 ms | 340 KB | Output is correct |
54 | Correct | 1 ms | 340 KB | Output is correct |
55 | Correct | 1 ms | 336 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 1 ms | 336 KB | Output is correct |
58 | Correct | 1 ms | 344 KB | Output is correct |
59 | Correct | 1 ms | 340 KB | Output is correct |
60 | Correct | 1 ms | 340 KB | Output is correct |
61 | Correct | 119 ms | 10144 KB | Output is correct |
62 | Correct | 117 ms | 10412 KB | Output is correct |
63 | Correct | 101 ms | 10060 KB | Output is correct |
64 | Correct | 123 ms | 10248 KB | Output is correct |
65 | Correct | 126 ms | 10260 KB | Output is correct |
66 | Correct | 122 ms | 10228 KB | Output is correct |
67 | Correct | 121 ms | 10144 KB | Output is correct |
68 | Correct | 90 ms | 10336 KB | Output is correct |
69 | Correct | 92 ms | 10144 KB | Output is correct |
70 | Correct | 86 ms | 10028 KB | Output is correct |