Submission #1340667

#TimeUsernameProblemLanguageResultExecution timeMemory
1340667justfadyFeast (NOI19_feast)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //  +
using namespace std;     // +++
#define inf 1e18         //  +
#define int __int64
#define all(a) a.begin(), a.end()
void files() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}

int const N = 3e5 + 5;
pair<int, int> dp[N][2];
int vis[N][2], id;
int n, k, a[N], lamda;
pair<int, int> rec(int i, bool lst) {
    if (i == n) return {0, 0};
    auto &ret = dp[i][lst];
    if (vis[i][lst] == id) return ret;
    vis[i][lst] = id;
    auto leave = rec(i + 1, 0);
    auto take = rec(i + 1, 1);
    take.first += a[i];
    if (!lst) {
        take.first -= lamda;
        take.second--;
    }

    return ret = max(leave, take);
}

void solve() {
    cin >> n >> k;

    for (int i = 0; i < n; ++i) cin >> a[i];

    int st = 0, en = 1e16, md, ans = 0;
    while (st <= en) {
        md = (st + en) / 2;

        lamda = md;
        ++id;
        auto [d, cnt] = rec(0, 0);

        int used = -cnt;
        if (used > k) st = md + 1;
        else {
            ans = d + lamda * k;
            en = md - 1;
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), files();
    int tc = 1;
    // cin >> tc;
    while (tc--)
        solve();
}

Compilation message (stderr)

feast.cpp:4:13: error: '__int64' does not name a type; did you mean '__int64_t'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:12:1: note: in expansion of macro 'int'
   12 | int const N = 3e5 + 5;
      | ^~~
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:13:6: note: in expansion of macro 'int'
   13 | pair<int, int> dp[N][2];
      |      ^~~
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:13:11: note: in expansion of macro 'int'
   13 | pair<int, int> dp[N][2];
      |           ^~~
feast.cpp:13:14: error: template argument 1 is invalid
   13 | pair<int, int> dp[N][2];
      |              ^
feast.cpp:13:14: error: template argument 2 is invalid
feast.cpp:13:19: error: 'N' was not declared in this scope
   13 | pair<int, int> dp[N][2];
      |                   ^
feast.cpp:4:13: error: '__int64' does not name a type; did you mean '__int64_t'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:14:1: note: in expansion of macro 'int'
   14 | int vis[N][2], id;
      | ^~~
feast.cpp:4:13: error: '__int64' does not name a type; did you mean '__int64_t'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:15:1: note: in expansion of macro 'int'
   15 | int n, k, a[N], lamda;
      | ^~~
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:16:6: note: in expansion of macro 'int'
   16 | pair<int, int> rec(int i, bool lst) {
      |      ^~~
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:16:11: note: in expansion of macro 'int'
   16 | pair<int, int> rec(int i, bool lst) {
      |           ^~~
feast.cpp:16:14: error: template argument 1 is invalid
   16 | pair<int, int> rec(int i, bool lst) {
      |              ^
feast.cpp:16:14: error: template argument 2 is invalid
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:16:20: note: in expansion of macro 'int'
   16 | pair<int, int> rec(int i, bool lst) {
      |                    ^~~
feast.cpp:16:27: error: expected primary-expression before 'bool'
   16 | pair<int, int> rec(int i, bool lst) {
      |                           ^~~~
feast.cpp:16:35: error: expression list treated as compound expression in initializer [-fpermissive]
   16 | pair<int, int> rec(int i, bool lst) {
      |                                   ^
feast.cpp: In function 'void solve()':
feast.cpp:33:12: error: 'n' was not declared in this scope; did you mean 'yn'?
   33 |     cin >> n >> k;
      |            ^
      |            yn
feast.cpp:33:17: error: 'k' was not declared in this scope
   33 |     cin >> n >> k;
      |                 ^
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:35:10: note: in expansion of macro 'int'
   35 |     for (int i = 0; i < n; ++i) cin >> a[i];
      |          ^~~
feast.cpp:35:21: error: 'i' was not declared in this scope
   35 |     for (int i = 0; i < n; ++i) cin >> a[i];
      |                     ^
feast.cpp:35:40: error: 'a' was not declared in this scope
   35 |     for (int i = 0; i < n; ++i) cin >> a[i];
      |                                        ^
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:37:5: note: in expansion of macro 'int'
   37 |     int st = 0, en = 1e16, md, ans = 0;
      |     ^~~
feast.cpp:38:12: error: 'st' was not declared in this scope; did you mean 'std'?
   38 |     while (st <= en) {
      |            ^~
      |            std
feast.cpp:38:18: error: 'en' was not declared in this scope; did you mean 'yn'?
   38 |     while (st <= en) {
      |                  ^~
      |                  yn
feast.cpp:39:9: error: 'md' was not declared in this scope
   39 |         md = (st + en) / 2;
      |         ^~
feast.cpp:41:9: error: 'lamda' was not declared in this scope; did you mean 'lgamma'?
   41 |         lamda = md;
      |         ^~~~~
      |         lgamma
feast.cpp:42:11: error: 'id' was not declared in this scope
   42 |         ++id;
      |           ^~
feast.cpp:43:28: error: 'rec' cannot be used as a function
   43 |         auto [d, cnt] = rec(0, 0);
      |                         ~~~^~~~~~
feast.cpp:45:13: error: expected ';' before 'used'
   45 |         int used = -cnt;
      |             ^~~~
feast.cpp:46:13: error: 'used' was not declared in this scope
   46 |         if (used > k) st = md + 1;
      |             ^~~~
feast.cpp:48:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |             ans = d + lamda * k;
      |             ^~~
      |             abs
feast.cpp:52:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |     cout << ans << '\n';
      |             ^~~
      |             abs
feast.cpp: In function 'int main()':
feast.cpp:4:13: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
    4 | #define int __int64
      |             ^~~~~~~
feast.cpp:57:5: note: in expansion of macro 'int'
   57 |     int tc = 1;
      |     ^~~
feast.cpp:59:12: error: 'tc' was not declared in this scope; did you mean 'tm'?
   59 |     while (tc--)
      |            ^~
      |            tm
feast.cpp: In function 'void files()':
feast.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:8:46: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~