結果

問題 No.77 レンガのピラミッド
ユーザー cureskol
提出日時 2020-03-27 07:06:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 162,464 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 08:13:01
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  int ans=1e9;
  for(int j=0;j<n;j++){
    int need=0,mv=0;
    for(int i=0;i<max(n,(j+1)*2);i++){
      int a=(i<n?v[i]:0);
      int b;
      if(i<=j)b=i+1;
      else b=j-(i-j)+1;
      if(b<0)b=0;
      if(b>a)need+=b-a;
      else mv+=a-b;
    }
    if(need>mv)continue;
    chmin(ans,mv);
  }
  cout<<ans<<endl;
}
0