結果

問題 No.77 レンガのピラミッド
コンテスト
ユーザー cureskol
提出日時 2020-03-27 07:06:16
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 511 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 965 ms
コンパイル使用メモリ 181,820 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-05 23:33:12
合計ジャッジ時間 2,136 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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