Submission #1295673

#TimeUsernameProblemLanguageResultExecution timeMemory
1295673thaibeo123Triple Jump (JOI19_jumps)C++20
19 / 100
267 ms239364 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define NAME "CONCERT"
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 5005;

int n, q;
int a[N], mx[N][N], dp[N][N];

void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
}

void solve() {
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            mx[i][j] = max(mx[i][j - 1], a[j]);
        }
    }
    for (int i = 1; i <= n - 2; i++) {
        dp[i][i + 2] = a[i] + a[i + 1] + a[i + 2];
    }
    for (int i = n; i >= 1; i--) {
        for (int j = i + 3; j <= n; j++) {
            int len = j - i + 1;
            dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
            int cur = a[i] + a[j] + mx[i + 1][i + (len - 1) / 2];
            dp[i][j] = max(dp[i][j], cur);
        }
    }
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << dp[l][r] << "\n";
    }
}

signed main() {
    if (fopen(NAME".INP", "r")) {
        freopen(NAME".INP", "r", stdin);
        freopen(NAME".OUT", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    input();
    solve();

    return 0;
}

Compilation message (stderr)

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