이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define sp " "
#define endl "\n"
#define mod 1000000007
#define MAXN 200005
#define MAXM 1000005
#define inf 1e18
#define INF 0x3f
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) for(auto& a: x) cout << a << " "
using namespace std;
typedef long long int lo;
lo arr[MAXN],dad[MAXN],sz[MAXN];
lo n,m,k;
vector<pair<lo,lo>> v[505];
string s;
void solve() {
cin >> n;
lo mx=0, mxind=0;
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
if(mx <= arr[i]){
mxind = i;
mx = arr[i];
}
}
vector<lo> duz(n+1,0);
vector<lo> preduz(n+1,0);
vector<lo> ters(n+1,0);
vector<lo> preters(n+1,0);
for (int i = 1; i < n; ++i)
{
if(arr[i] <= arr[i-1]+duz[i-1]){
duz[i] = arr[i-1]-arr[i]+duz[i-1]+1;
}
preduz[i] = max(preduz[i-1],duz[i]);
}
for (int i = n-2; i >= 0; i--)
{
if(arr[i] <= arr[i+1]+ters[i+1]){
ters[i] = arr[i+1]-arr[i]+ters[i+1]+1;
}
preters[i] = max(preters[i+1],ters[i]);
}
// debug(preduz);
// cout << endl;
// debug(preters);
// cout << endl;
lo ans = inf;
for (int i = 0; i < n; ++i)
{
ans = min(ans,max(preters[i],preduz[i]));
}
cout << ans << endl;
}
int main()
{
// cout << fixed << setprecision(12);
// freopen("snowboots.in","r",stdin);
// freopen("snowboots.out","w",stdout);
fast;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
// cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:27:14: warning: variable 'mxind' set but not used [-Wunused-but-set-variable]
27 | lo mx=0, mxind=0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |