답안 #502747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502747 2022-01-06T14:27:33 Z amunduzbaev 3단 점프 (JOI19_jumps) C++14
0 / 100
114 ms 42504 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 0;
		int lg = __lg(r - l + 1);
		return max(mx[l][lg], mx[r - (1 << lg) + 1][lg]);
	};
	
	auto check = [&](int l, int r){
		int res = a[l] + a[r];
		res += max({get(l + 1, (r - l) / 2), get(max(1ll, l - (r - l)), l - 1), get(r + 1, min(n, r + (r - l)))});
		return res;
	};
	
	int B = min(n, 400ll);
	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";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 42456 KB Output is correct
2 Incorrect 90 ms 42504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -