제출 #1102418

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
11024182024-10-18 06:01:50NotLinuxGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms508 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int inf = 1e18 + 7;
void solve(){
int n;
cin >> n;
int arr[n];
for(int i = 0;i<n;i++)cin >> arr[i];
int pre[n]={0} , suf[n]={0};
int preval[n] , sufval[n];
preval[0] = arr[0];
for(int i = 1;i<n;i++){
pre[i] = pre[i-1] + max(0ll , preval[i-1] + 1 - arr[i]);
preval[i] = max(arr[i] , preval[i-1] + 1);
}
sufval[n-1] = arr[n-1];
for(int i = n-2;i>=0;i--){
suf[i] = suf[i+1] + max(0ll , sufval[i+1] + 1 - arr[i]);
sufval[i] = max(arr[i] , sufval[i+1] + 1);
}
int global_ans = inf;
for(int i = 0;i<n;i++){
int ans[3];
ans[0] = (i == 0 ? 0ll : pre[i-1]);
ans[1] = max(i == 0 ? 0ll : preval[i-1] , i == n-1 ? 0ll : sufval[i+1]) + 1 - arr[i];
ans[2] = (i == n-1 ? 0ll : suf[i+1]);
int total = ans[0] + ans[1] + ans[2];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...