답안 #1113206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113206 2024-11-16T03:48:21 Z HiepVu217 Feast (NOI19_feast) C++17
100 / 100
119 ms 9456 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define int long long
using namespace std;
const int N = 3e5 + 17;
int n, k;
long long a[N];
pair <long long, int> f[N], m;
inline pair <long long, int> calc (int c)
{
    f[0] = m = {0, 0};
    for (int i = 1; i <= n; ++i)
    {
        f[i] = f[i - 1];
        if (m.first + a[i] - c > f[i].first || (m.first + a[i] - c == f[i].first && m.second + 1 < f[i].second))
        {
            f[i].first = m.first + a[i] - c;
            f[i].second = m.second + 1;
        }
        if (f[i].first - a[i] > m.first || (f[i].first - a[i] == m.first && f[i].second < m.second))
        {
            m.first = f[i].first - a[i];
            m.second = f[i].second;
        }
    }
    return f[n];
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    long long l = 1, r = 3e14;
    while (l < r)
    {
        long long mid = l + r + 1 >> 1;
        m = calc (mid);
        if (m.second >= k)
        {
            l = mid;
            continue;
        }
        r = mid - 1;
    }
    m = calc(l);
    long long ans = l * m.second + m.first;
    cout << ans;
}

Compilation message

feast.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
feast.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
feast.cpp: In function 'int32_t main()':
feast.cpp:43:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         long long mid = l + r + 1 >> 1;
      |                         ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 7248 KB Output is correct
2 Correct 61 ms 9192 KB Output is correct
3 Correct 48 ms 7452 KB Output is correct
4 Correct 49 ms 8776 KB Output is correct
5 Correct 48 ms 7248 KB Output is correct
6 Correct 50 ms 7828 KB Output is correct
7 Correct 51 ms 8788 KB Output is correct
8 Correct 64 ms 7240 KB Output is correct
9 Correct 49 ms 8520 KB Output is correct
10 Correct 51 ms 7752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 7248 KB Output is correct
2 Correct 39 ms 8264 KB Output is correct
3 Correct 39 ms 7812 KB Output is correct
4 Correct 48 ms 8008 KB Output is correct
5 Correct 57 ms 7252 KB Output is correct
6 Correct 36 ms 7504 KB Output is correct
7 Correct 39 ms 8016 KB Output is correct
8 Correct 47 ms 8084 KB Output is correct
9 Correct 44 ms 7980 KB Output is correct
10 Correct 37 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 7348 KB Output is correct
2 Correct 64 ms 7496 KB Output is correct
3 Correct 63 ms 7248 KB Output is correct
4 Correct 60 ms 7752 KB Output is correct
5 Correct 70 ms 7240 KB Output is correct
6 Correct 61 ms 8004 KB Output is correct
7 Correct 63 ms 7836 KB Output is correct
8 Correct 80 ms 8520 KB Output is correct
9 Correct 59 ms 7368 KB Output is correct
10 Correct 60 ms 7240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 1 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 7248 KB Output is correct
2 Correct 61 ms 9192 KB Output is correct
3 Correct 48 ms 7452 KB Output is correct
4 Correct 49 ms 8776 KB Output is correct
5 Correct 48 ms 7248 KB Output is correct
6 Correct 50 ms 7828 KB Output is correct
7 Correct 51 ms 8788 KB Output is correct
8 Correct 64 ms 7240 KB Output is correct
9 Correct 49 ms 8520 KB Output is correct
10 Correct 51 ms 7752 KB Output is correct
11 Correct 36 ms 7248 KB Output is correct
12 Correct 39 ms 8264 KB Output is correct
13 Correct 39 ms 7812 KB Output is correct
14 Correct 48 ms 8008 KB Output is correct
15 Correct 57 ms 7252 KB Output is correct
16 Correct 36 ms 7504 KB Output is correct
17 Correct 39 ms 8016 KB Output is correct
18 Correct 47 ms 8084 KB Output is correct
19 Correct 44 ms 7980 KB Output is correct
20 Correct 37 ms 7248 KB Output is correct
21 Correct 66 ms 7348 KB Output is correct
22 Correct 64 ms 7496 KB Output is correct
23 Correct 63 ms 7248 KB Output is correct
24 Correct 60 ms 7752 KB Output is correct
25 Correct 70 ms 7240 KB Output is correct
26 Correct 61 ms 8004 KB Output is correct
27 Correct 63 ms 7836 KB Output is correct
28 Correct 80 ms 8520 KB Output is correct
29 Correct 59 ms 7368 KB Output is correct
30 Correct 60 ms 7240 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 2 ms 336 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 2 ms 336 KB Output is correct
60 Correct 1 ms 504 KB Output is correct
61 Correct 119 ms 9032 KB Output is correct
62 Correct 105 ms 9188 KB Output is correct
63 Correct 102 ms 9088 KB Output is correct
64 Correct 111 ms 8996 KB Output is correct
65 Correct 108 ms 9260 KB Output is correct
66 Correct 114 ms 9420 KB Output is correct
67 Correct 108 ms 9032 KB Output is correct
68 Correct 73 ms 9456 KB Output is correct
69 Correct 69 ms 9032 KB Output is correct
70 Correct 69 ms 9228 KB Output is correct