Submission #489505

#TimeUsernameProblemLanguageResultExecution timeMemory
489505wiwihoTriple Jump (JOI19_jumps)C++14
5 / 100
4051 ms524292 KiB
#include<bits/stdc++.h> #define mp make_pair #define F first #define S second #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n";\ } #define eb emplace_back using namespace std; typedef long long ll; using pii = pair<int, int>; using pll = pair<ll, ll>; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(n + 1); for(int i = 1; i <= n; i++) cin >> a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(n + 1)); for(int i = 1; i + 2 <= n; i++){ ll mx = a[i + 1]; int p = i + 1; for(int j = i + 2; j <= n; j++){ for(int k = i + 1; k < j; k++){ if(k - i <= j - k) dp[i][j] = max(dp[i][j], a[i] + a[j] + a[k]); } } /*for(int j = i + 2; j <= n; j++){ while(p + 1 - i <= j - p - 1){ mx = max(mx, a[p]); p++; } //cerr << i << " " << j << " " << p << "\n"; dp[i][j] = a[i] + a[j] + mx; }*/ } /*for(int len = 3; len <= n; len++){ for(int i = 1; i + len <= n; i++){ int j = i + len; dp[i][j] = max({dp[i][j], dp[i][j - 1], dp[i + 1][j]}); } }*/ int q; cin >> q; while(q--){ int l, r; cin >> l >> r; ll ans = 0; for(int i = l; i + 2 <= r; i++){ for(int j = i + 2; j <= r; j++){ ans = max(ans, dp[i][j]); } } cout << ans << "\n"; } return 0; }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:32:12: warning: unused variable 'mx' [-Wunused-variable]
   32 |         ll mx = a[i + 1];
      |            ^~
jumps.cpp:33:13: warning: unused variable 'p' [-Wunused-variable]
   33 |         int p = i + 1;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...