Submission #164570

#TimeUsernameProblemLanguageResultExecution timeMemory
164570AMeyburghKrov (COCI17_krov)C++17
70 / 140
1562 ms4020 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i_,a_) for(int i_=0;i_<a_;++i_) #define FORS(s_,i_,a_) for(int i_=s_;i_<a_;++i_) #define FORR(i_,a_) for(int i_=a_-1;i_>=0;--i_) #define FORI(i_,a_) for(int i_=1;i_<=a_;++i_) #define FORA(i_,a_) for(auto i_:a_) #define FOR1(i_,a_) for(int i_=1;i_<a_;++i_) #define FORIT(it_,c_) for(auto it_ = c_.begin(); it_!=c_.end();++it_) #define _ cerr<<' '; #define _N cerr<<'\n'; #define _T cerr<<'\t'; #define TRACED(_v) cerr<<_v; void TRACEV(string a){TRACED(a);} template<typename... Args> void TRACEV(tuple<Args...> t); template<typename l, typename r> void TRACEV(pair<l,r> t); template<typename T> void TRACEV(T t){TRACED(t);} template<template<typename...> class T, typename... K> void TRACEV(T<K...> t); template<typename T, size_t S> void TRACEV(array<T,S> t){TRACEV("[");TRACEV(t[0]);FOR1(i,S){TRACEV(", ");TRACEV(t[i]);}TRACEV("]");} template<typename T,typename... Args>void TRACEUT_(T t){TRACEV(t);} template<typename T,typename... Args>void TRACEUT_(T t, Args... args){TRACEV(t); TRACED(", "); TRACEUT_(args...);} template<typename T,typename... Args>void TRACEUT(T t, Args... args){TRACED('('); TRACEUT_(t,args...); TRACED(")");} template<typename Tuple, size_t... Is>void TRACET_(Tuple t, index_sequence<Is...>){TRACEUT(get<Is>(t)...);} template<typename Tuple>void TRACET(Tuple t){TRACET_(t,make_index_sequence<tuple_size<Tuple>::value>{});} #define TRACEP(p_) TRACED("("); TRACEV(p_.first);TRACED(", ");TRACEV(p_.second);TRACED(")"); template<typename... Args> void TRACEV(tuple<Args...> t){TRACET(t);} template<typename l, typename r> void TRACEV(pair<l,r> t){TRACEP(t);} template<template<typename...> class T, typename... K> void TRACEV(T<K...> t){auto it = t.begin(); TRACED("[");TRACEV(*it);for(++it;it!=t.end();++it){TRACED(", ");TRACEV(*it);}TRACED("]");} template<typename T> void TRACE(T t){TRACEV(t);_N;} template<typename T,typename... Ts> void TRACE(T t,Ts... args){TRACEV(t); _T; TRACE(args...);} #define ll long long int #define ull unsigned long long int #define pii pair<int,int> #define INF LLONG_MAX; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector<ll> heights(N); FOR(i,N) cin>>heights[i]; ll MIN = INF; FOR(i,N){ vector<ll> ks(N); FOR(j,N) ks[j] = heights[j] + abs(j-i); sort(ks.begin(),ks.end()); vector<ll> sum(N); sum[0] = ks[0]; FOR1(j,N) sum[j] = sum[j-1] + ks[j]; ll X; ll minX = max(i,N-1-i)+1; FOR(p,N){ if(p == N-1 || ks[p] != ks[p+1]){ if(2*p+2 < N-1){ X = max(ks[p+1]-1,minX); } else{ X = max(ks[p],minX); } if(X >= ks[p]){ MIN = min(MIN,X*(2*p+2-N) + sum[N-1] - 2*sum[p]); } } } } cout<<MIN<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...