답안 #773575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773575 2023-07-05T06:56:10 Z CyberCow 3단 점프 (JOI19_jumps) C++17
0 / 100
4 ms 724 KB
//#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

jumps.cpp: In function 'void solve()':
jumps.cpp:34:24: warning: unused variable 'm' [-Wunused-variable]
   34 |     int n, i, j, x, y, m;
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -