Submission #1100352

# Submission time Handle Problem Language Result Execution time Memory
1100352 2024-10-13T14:46:09 Z baoquan Triple Jump (JOI19_jumps) C++14
19 / 100
288 ms 180864 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 4;
const int maxm = 5e3 + 4;
int a[maxn] , n , m , dp[maxm][maxm] , ma[maxm][maxm];
int l[maxn] , r[maxn];

void nhap()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1 ; i <= n ; i ++)
        cin >> a[i];
    cin >> m;
    for (int i = 1 ; i <= m ; i ++)
        cin >> l[i] >> r[i];
}

void xl1(int l , int r)
{
    int ans = 0;
    for (int i = l ; i <= r - 2 ; i ++)
    {
        for (int j = i + 1 ; j <= r - 1 ; j ++)
        {
            for (int k = j + (j - i) ; k <= r ; k ++)
            {
                ans = max(ans , a[i] + a[j] + a[k]);
            }
        }
    }
    cout << ans << '\n';
}

void Sub1()
{
    for (int i = 1 ; i <= m ; i ++)
    {
        xl1(l[i] , r[i]);
    }
}

void Sub2()
{
    for (int i = 1 ; i <= n ; i ++)
        ma[i][i] = a[i];
    for (int i = 1 ; i < n ; i ++)
        for (int j = i + 1 ; j <= n ; j ++)
        {
            ma[i][j] = max(ma[i][j - 1] , a[j]);
        }
    for (int i = 2 ; i < n ; i ++)
    {
        for (int j = 1 ; j <= n - i ; j ++)
        {
            int l = j;
            int r = j + i;
            dp[l][r] = max(dp[l][r - 1] , max(dp[l + 1][r] , a[l] + a[r] + ma[l + 1][(l + r) / 2]));
        }
    }
    for (int i = 1 ; i <= m ; i ++)
    {
        cout << dp[l[i]][r[i]] << '\n';
    }
}

signed main()
{
    nhap();
    if (n <= 100 && m <= 100)
        Sub1();
    else
        if (n <= 5000)
        Sub2();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 263 ms 176268 KB Output is correct
12 Correct 280 ms 180740 KB Output is correct
13 Correct 273 ms 180812 KB Output is correct
14 Correct 287 ms 180812 KB Output is correct
15 Correct 288 ms 180812 KB Output is correct
16 Correct 282 ms 180300 KB Output is correct
17 Correct 278 ms 180300 KB Output is correct
18 Correct 244 ms 180300 KB Output is correct
19 Correct 240 ms 180864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 263 ms 176268 KB Output is correct
12 Correct 280 ms 180740 KB Output is correct
13 Correct 273 ms 180812 KB Output is correct
14 Correct 287 ms 180812 KB Output is correct
15 Correct 288 ms 180812 KB Output is correct
16 Correct 282 ms 180300 KB Output is correct
17 Correct 278 ms 180300 KB Output is correct
18 Correct 244 ms 180300 KB Output is correct
19 Correct 240 ms 180864 KB Output is correct
20 Incorrect 16 ms 4432 KB Output isn't correct
21 Halted 0 ms 0 KB -