Submission #811753

# Submission time Handle Problem Language Result Execution time Memory
811753 2023-08-07T05:42:26 Z vjudge1 Triple Jump (JOI19_jumps) C++14
0 / 100
18 ms 2016 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const int N = 5e5, NS = 5e3 ;
int n, q, d[N + 1], dp[NS + 1][NS + 1], mx[NS + 1][NS + 1] ;
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    for(int i = 1 ; i <= n ; i++)
        cin >> d[i] ;
    cin >> q ;
    if(n <= 5000)
    {
        for(int i = 1 ; i <= n ; i++)
            for(int j = i ; j <= n ; j++)
                mx[i][j] = max(mx[i][j - 1], d[j]) ;
        for(int i = 1 ; i <= n - 2 ; i++)
            dp[i][i + 2] = d[i] + d[i + 1] + d[i + 2] ;
        for(int ln = 4 ; ln <= n ; ln++)
            for(int j = 1 ; j <= n - ln + 1 ; j++)
                dp[j][j + ln - 1] = max({dp[j][j + ln - 2], dp[j + 1][j + ln - 1], d[j] + d[j + ln - 1] + mx[j + 1][j + (ln - 2) / 2]}) ;
//        for(int ln = 3 ; ln <= n ; ln++)
//        {
//            for(int j = 1 ; j <= n - ln + 1 ; j++)
//                cout << dp[j][j + ln - 1] << ' ' ;
//            cout << '\n' ;
//        }
        while(q--)
        {
            int l, r ;
            cin >> l >> r ;
            cout << dp[l][r] << '\n' ;
        }
        return 0 ;
    }
    if(n <= 100 && q <= 100)
    {
        while(q--)
        {
            int l, r, ans = 0 ;
            cin >> l >> r ;
            for(int b = l + 1 ; b < r ; b++)
                for(int a = l ; a < b ; a++)
                    for(int c = b + (b - a) ; c <= r ; c++)
                        ans = max(ans, d[a] + d[b] + d[c]) ;
            cout << ans << '\n' ;
        }
        return 0 ;
    }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -