답안 #502765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502765 2022-01-06T14:54:38 Z amunduzbaev 3단 점프 (JOI19_jumps) C++14
0 / 100
160 ms 42960 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(min(n + 1, r + (r - l)), n)});
		return res;
	};
	
	int B = min(n, 1000ll);
	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 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 42492 KB Output is correct
2 Correct 88 ms 42468 KB Output is correct
3 Correct 89 ms 42960 KB Output is correct
4 Correct 153 ms 42940 KB Output is correct
5 Correct 156 ms 42716 KB Output is correct
6 Incorrect 133 ms 42716 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -