Submission #1362202

#TimeUsernameProblemLanguageResultExecution timeMemory
1362202adscodingDischarging (NOI20_discharging)C++20
36 / 100
1095 ms16304 KiB
#include <bits/stdc++.h>
#define pb emplace_back
#define SZ(x) ((int)x.size())
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __prine_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        cerr << "  ,  ";
        ++s;
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = {0, (__prine_one(s, args), 0)...};
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, const X &b)
{
    if (b > a)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, const X &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

constexpr int maxn = 1e6 + 3;
int n, opt[maxn];
ll a[maxn], dp[maxn];


// --------------------------------------------------------------------------------------------


void readInput()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> a[i];
        dp[i] = 1e18;
    }
}

void solve()
{
    opt[0] = 1;
    FOR(i, 1, n)
    {
        ll ma = -1e18;
        FORD(j, i, opt[i - 1])
        {
            maximize(ma, a[j]);
            if (minimize(dp[i], dp[j - 1] + ma * (n - j + 1)))
                opt[i] = j;
        }
    }

    cout << dp[n];
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message (stderr)

Discharging.cpp: In function 'int main()':
Discharging.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...