답안 #791849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791849 2023-07-24T11:10:41 Z vjudge1 Feast (NOI19_feast) C++17
0 / 100
72 ms 11248 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x, i) (1 & ((x) >> (i)))
#define MASK(x) (1LL << (x))
#define task "tnc"
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef long double ld;
const ll INF = 1e14;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int mo = 998244353;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll n, k;
ll a[maxn];
ll dp[maxn];
ll trace[maxn];
ll pre[maxn];
ll f(ll mid)
{
    // dp[i] = max(dp[i-1],dp[j]+dp[i]-pre[j]+pre[i]-mid);
    dp[0] = 0;
    ll ma = 0;
    ll vt = 0;
    trace[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        dp[i] = 0;
        trace[i] = 0;
    }

    for (int i = 1; i <= n; i++)
    {

        if (dp[i - 1] <= ma + pre[i] - mid)
        {
            dp[i] = ma + pre[i] - mid;
            trace[i] = trace[vt] + 1;
        }
        else
        {
            trace[i] = trace[i - 1];
        }
        if (ma <= dp[i] - pre[i])
        {
            ma = dp[i] - pre[i];
            vt = i;
        }
    }
    return trace[n];
}
void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    ll l = 0;
    ll r = INF;
    ll ans;
    ll ans1;
    while (l <= r)
    {
        ll mid = (l + r) / 2;
        if (f(mid) <= k)
        {
            ans = dp[n];
            ans1 = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    cout << ans + ans1 * k;
}
signed main()
{
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);

    solve();
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:97:24: warning: 'ans1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   97 |     cout << ans + ans1 * k;
      |                   ~~~~~^~~
feast.cpp:97:26: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   97 |     cout << ans + ans1 * k;
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 11084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 10504 KB Output is correct
2 Correct 45 ms 10804 KB Output is correct
3 Incorrect 44 ms 10612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 11248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 11084 KB Output isn't correct
2 Halted 0 ms 0 KB -