Submission #1013045

# Submission time Handle Problem Language Result Execution time Memory
1013045 2024-07-03T06:29:10 Z aliarapov Triple Jump (JOI19_jumps) C++17
5 / 100
4000 ms 33152 KB
#include <bits/stdc++.h>
 
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
 
using namespace std;
 
const int INF = 1e9;
const int mod = 998244353;
const int N = 200005;
int sp[N][20];
 
int get(int l, int r){
	int lg = __lg(r - l + 1);
	return max(sp[l][lg], sp[r - (1ll << lg) + 1][lg]);
}
 
void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		sp[i][0] = a[i];
	}
	for(int i = 1; i < 20; i++){
		for(int j = 0; j < n; j++){
			sp[j][i] = max(sp[j][i - 1], sp[min(n - 1, j + (1ll << (i - 1)))][i - 1]);
		}
	}
	int q;
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		int ans = 0;
		for(int i = l; i < r - 1; i++){
			for(int j = i + 1; j < r; j++){
				if(j + (j - i) <= r) ans = max(ans, a[i] + a[j] + get(j + (j - i), r));
			}
		}
		
		cout << ans << '\n';
	}
}
 
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int tt = 1;
    //cin >> tt;
    while(tt--){
		solve();
	}
}

Compilation message

jumps.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Execution timed out 4045 ms 1388 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4046 ms 33152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Execution timed out 4045 ms 1388 KB Time limit exceeded
12 Halted 0 ms 0 KB -