답안 #1113199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113199 2024-11-16T03:38:58 Z HiepVu217 Feast (NOI19_feast) C++17
컴파일 오류
0 ms 0 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 (long long 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;
        m = calc (mid);
        if (m.second == k)
        {
            cout << mid * k + m.first;
            return 0;
        }
        if (m.second > k)
        {
            l = mid + 1;
            continue;
        }
        r = mid - 1;
    }
    long long ans = l * k + calc(l).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:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
feast.cpp:6:7: note: in expansion of macro 'int'
    6 | const int N = 3e5 + 17;
      |       ^~~
feast.cpp:6:11: error: 'N' does not name a type
    6 | const int N = 3e5 + 17;
      |           ^
feast.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
feast.cpp:7:1: note: in expansion of macro 'int'
    7 | int n, k;
      | ^~~
feast.cpp:7:5: error: 'n' does not name a type; did you mean 'yn'?
    7 | int n, k;
      |     ^
      |     yn
feast.cpp:8:13: error: 'N' was not declared in this scope
    8 | long long a[N];
      |             ^
feast.cpp:4:18: error: template argument 2 is invalid
    4 | #define int long long;
      |                  ^~~~
feast.cpp:9:18: note: in expansion of macro 'int'
    9 | pair <long long, int> f[N], m;
      |                  ^~~
feast.cpp:9:21: error: expected unqualified-id before '>' token
    9 | pair <long long, int> f[N], m;
      |                     ^
feast.cpp:4:18: error: template argument 2 is invalid
    4 | #define int long long;
      |                  ^~~~
feast.cpp:10:25: note: in expansion of macro 'int'
   10 | inline pair <long long, int> calc (long long c)
      |                         ^~~
feast.cpp:10:1: error: 'inline' can only be specified for functions
   10 | inline pair <long long, int> calc (long long c)
      | ^~~~~~
feast.cpp:10:28: error: expected unqualified-id before '>' token
   10 | inline pair <long long, int> calc (long long c)
      |                            ^
feast.cpp: In function 'int32_t main()':
feast.cpp:34:12: error: 'n' was not declared in this scope; did you mean 'yn'?
   34 |     cin >> n >> k;
      |            ^
      |            yn
feast.cpp:34:17: error: 'k' was not declared in this scope
   34 |     cin >> n >> k;
      |                 ^
feast.cpp:4:18: error: declaration does not declare anything [-fpermissive]
    4 | #define int long long;
      |                  ^~~~
feast.cpp:35:10: note: in expansion of macro 'int'
   35 |     for (int i = 1; i <= n; ++i)
      |          ^~~
feast.cpp:35:14: error: 'i' was not declared in this scope
   35 |     for (int i = 1; i <= n; ++i)
      |              ^
feast.cpp:35:27: error: expected ')' before ';' token
   35 |     for (int i = 1; i <= n; ++i)
      |         ~                 ^
      |                           )
feast.cpp:35:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   35 |     for (int i = 1; i <= n; ++i)
      |     ^~~
feast.cpp:35:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   35 |     for (int i = 1; i <= n; ++i)
      |                             ^~
feast.cpp:35:31: error: 'i' was not declared in this scope
   35 |     for (int i = 1; i <= n; ++i)
      |                               ^
feast.cpp:43:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         long long mid = l + r >> 1;
      |                         ~~^~~
feast.cpp:44:9: error: 'm' was not declared in this scope
   44 |         m = calc (mid);
      |         ^
feast.cpp:44:13: error: 'calc' was not declared in this scope
   44 |         m = calc (mid);
      |             ^~~~
feast.cpp:57:29: error: 'calc' was not declared in this scope
   57 |     long long ans = l * k + calc(l).first;
      |                             ^~~~