Submission #502871

# Submission time Handle Problem Language Result Execution time Memory
502871 2022-01-06T16:39:30 Z amunduzbaev Triple Jump (JOI19_jumps) C++14
0 / 100
1486 ms 44404 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define int long long
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<int> a(n + 1);
	for(int i=1;i<=n;i++) cin>>a[i];
	
	vector<int> p(n);
	for(int i=0;i<n;i++) p[i] = i + 1;
	sort(p.begin(), p.end(), [&](int i, int j){
		return (a[i] > a[j]);
	});
	
	vector<vector<int>> mx(n + 1, vector<int>(20));
	for(int i=1;i<=n;i++) mx[i][0] = a[i];
	for(int j=1;j<20;j++){
		for(int i=1;i + (1 << (j - 1))<=n;i++){
			mx[i][j] = max(mx[i][j-1], mx[i + (1 << (j - 1))][j-1]);
		}
	}
	
	auto get = [&](int l, int r) -> int{
		if(l > r) return -2e9;
		int lg = __lg(r - l + 1);
		return max(mx[l][lg], mx[r - (1 << lg) + 1][lg]);
	};
	
	auto check = [&](int l, int r){
		if(l > r) swap(l, r);
		int res = a[l] + a[r];
		//~ cout<<l + 1<<" "<<(l + r) / 2<<", "<<max(1ll, l - (r - l))<<" "<<l - 1<<", "<<min(n + 1, r + (r - l))<<" "<<n<<endl;
		res += max({get(l + 1, (l + r) / 2), get(max(1ll, l - (r - l)), l - 1), get(r + (r - l), n)});
		return res;
	};
	
	int B = min(n, 5000ll);
	int res = 0;
	for(int i=0;i<B;i++){
		for(int j=i+1;j<B;j++){
			res = max(res, check(p[i], p[j]));
		}
	}
	
	cout<<res<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Incorrect 0 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Incorrect 0 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1415 ms 44332 KB Output is correct
2 Correct 239 ms 44404 KB Output is correct
3 Correct 256 ms 44220 KB Output is correct
4 Correct 1433 ms 44352 KB Output is correct
5 Correct 1486 ms 44320 KB Output is correct
6 Incorrect 898 ms 43660 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Incorrect 0 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -