# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
773575 | CyberCow | Triple Jump (JOI19_jumps) | C++17 | 4 ms | 724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#include <bits/stdc++.h>
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 5005;
int a[N];
int dp[N][N];
void solve()
{
int n, i, j, x, y, m;
cin >> n;
for ( i = 1; i <= n; i++)
{
cin >> a[i];
}
for ( i = 2; i <= n; i++)
{
int ma = 0;
for (j = i + 1; j <= n; j++)
{
if (i - (j - i) >= 1)
{
ma = max(ma, a[i - (j - i)]);
}
dp[max(1, i - (j - i))][j] = max(dp[max(1, i - (j - i))][j], ma + a[i] + a[j]);
}
}
for ( i = 2; i <= n; i++)
{
for ( j = 1; j <= n; j++)
{
dp[j][j + i - 1] = max(dp[j][j + i - 1], max(dp[j + 1][j + i - 1], dp[j][j + i - 2]));
}
}
int q;
cin >> q;
for ( i = 0; i < q; i++)
{
cin >> x >> y;
cout << dp[x][y] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |