답안 #600365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600365 2022-07-20T19:16:18 Z 1ne Growing Vegetables is Fun 4 (JOI21_ho_t1) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;cin>>n;
	vector<long long>arr(n);
	for (int i = 0;i<n;++i){
		cin>>arr[i];
	}
	vector<long long>pref(n),suff(n);
	vector<long long>prefmax(n),suffmax(n);
	vector<long long>maxxy(n,0),maxxy2(n,0);
	prefmax[0] = arr[0];
	for (int i = 1;i<n;++i){
		prefmax[i] = max(prefmax[i - 1] + 1,arr[i]);
	}
	suffmax[n - 1] = arr[n - 1];
	for (int i = n - 2;i>=0;--i){
		suffmax[i] = max(suffmax[i + 1] + 1,arr[i]);
	}
	pref[0] = 0;
	long long  h = 0;
	for (int i =1;i<n;++i){
		long long needed = max(0LL,prefmax[i - 1] + 1 - arr[i]);
		pref[i] = pref[i - 1] + max(0LL,prefmax[i - 1] + 1 - arr[i] - h);
		maxxy[i] = max(maxxy[i - 1],max(0LL,prefmax[i - 1] + 1 - arr[i] - h));
		h = needed;
	}
	h = 0;
	suff[n - 1] = 0;
	for (int i =n - 2;i>=0;--i){
		long long needed = max(0LL,suffmax[i + 1] + 1 - arr[i]);
		suff[i] = suff[i + 1] + max(0LL,suffmax[i + 1] + 1 - arr[i] - h);
		maxxy2[i] = max(maxxy2[i + 1],max(0LL,suffmax[i + 1] + 1 - arr[i] - h));
		h = needed;
	}
	long long ans = 1e15;
	for (int i = 0;i<n - 1;++i){
		ans = min(ans,pref[i] + suff[i + 1] + max(0LL,suffmax[i + 1] + 1 - prefmax[i]) - min(maxxy[i],maxxy2[i + 1]));
	}
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -