Submission #515520

#TimeUsernameProblemLanguageResultExecution timeMemory
51552079brueTriple Jump (JOI19_jumps)C++14
5 / 100
4057 ms4824 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, q; int arr[500002]; int DP[5002][5002]; int DPmax[5002][5002]; void solveSmall(){ for(int i=1; i<=n; i++){ DPmax[i][i] = arr[i]; for(int j=i+1; j<=n; j++){ DPmax[i][j] = max(DPmax[i][j-1], arr[j]); } } for(int i=1; i<=n-2; i++) DP[i][i+2] = arr[i] + arr[i+1] + arr[i+2]; for(int d=3; d<n; d++){ for(int i=1; i+d<=n; i++){ int j = i+d; DP[i][j] = max({DP[i][j-1], DP[i+1][j], arr[i] + arr[j] + DPmax[i+1][(i+j)/2]}); } } scanf("%d", &q); while(q--){ int l, r; scanf("%d %d", &l, &r); printf("%d\n", DP[l][r]); } exit(0); } int main(){ scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &arr[i]); // if(n <= 5000) solveSmall(); scanf("%d", &q); while(q--){ int l, r; scanf("%d %d", &l, &r); int ans = 0; for(int a=l; a<=r-2; a++){ vector<pair<int, int> > vec; for(int j=a+1; j<=r; j++) vec.push_back(make_pair(arr[j], j)); sort(vec.rbegin(), vec.rend()); for(int j=0; j<(int)vec.size() && j<20; j++){ for(int k=a+1; k<=r; k++){ if(vec[j].second == k) continue; int b = min(vec[j].second, k); int c = max(vec[j].second, k); if(b-a <= c-b) ans = max(ans, arr[a]+arr[b]+arr[c]); } } } printf("%d\n", ans); } }

Compilation message (stderr)

jumps.cpp: In function 'void solveSmall()':
jumps.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
jumps.cpp: In function 'int main()':
jumps.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:38:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~
jumps.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jumps.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...