| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1355781 | truongthaiduonglaptrinh | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 344 KiB |
// duonglaptrinh
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n;
long long a[N], l[N], r[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("nhap.inp", "r")) {
freopen("nhap.inp", "r", stdin);
freopen("nhap.out", "w", stdout);
}
cin>>n;
for(int i = 1; i <= n; i++) {
cin>>a[i];
}
int i = 1, last = 0, s = 0;
while(i <= n) {
if(last) {
s += abs(a[i] - a[last]) + 1;
}
l[i] = s;
int j = i + 1;
while(j <= n && a[j - 1] < a[j]) {
l[j] = s;
j++;
}
last = j - 1;
i = j;
}
i = n, last = 0, s = 0;
while(i >= 1) {
if(last) {
s += abs(a[i] - a[last]) + 1;
}
r[i] = s;
int j = i - 1;
while(j >= 1 && a[j] > a[j + 1]) {
r[j] = s;
j--;
}
last = j + 1;
i = j;
}
long long ans = l[n];
for(int i = 1; i <= n; i++) {
// cout<<l[i]<<" "<<r[i]<<"\n";
ans = min(ans, max(l[i], r[i]));
}
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
