fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll=long long;
  4. const ll INF=(ll)4e18;
  5. int main(){ios::sync_with_stdio(0);cin.tie(0);
  6. int N; if(!(cin>>N)) return 0;
  7. vector<ll>T(N),c(N,INF); priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<>>q;
  8. for(int i=0;i<N;i++){cin>>T[i]; c[i]=T[i]; q.push({c[i],i});}
  9. while(!q.empty()){
  10. auto [t,u]=q.top(); q.pop(); if(t!=c[u]) continue;
  11. for(int d:{-1,1}){
  12. int v=u+d; if(v<0||v>=N) continue;
  13. ll x=t+T[v]/2; if(x<c[v]){c[v]=x; q.push({x,v});}
  14. int other = v + (d==1?1:-1); // <- 여기서 '다른 쪽 이웃'을 정확히 계산
  15. if(other>=0 && other<N && c[other]<INF){
  16. x = max(t,c[other]) + T[v]/4;
  17. if(x<c[v]){c[v]=x; q.push({x,v});}
  18. }
  19. }
  20. }
  21. cout<<*max_element(c.begin(),c.end())<<"\n";
  22. }
Success #stdin #stdout 0.01s 5276KB
stdin
3
1 8 20
stdout
15