結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2014-11-27 00:10:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 771 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 71,848 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-03 09:12:41 |
合計ジャッジ時間 | 1,865 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <numeric> #include <string> #include <vector> #define rep(x,to) for(int (x)=0;(x)<(to);(x)++) #define repf(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++) using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; int res = 1<<29; int lm = (int)sqrt(accumulate(a.begin(),a.end(),0)); for(;lm;lm--){ int ki=0; vector<int> oo(220,0); oo[0]=1; repf(i,1,2*lm-1) oo[i] = i<lm? oo[i-1]+1: oo[i-1]-1; //for(auto x :oo) if(x) printf("%d, ",x); puts(""); rep(i,n){ if(a[i] > oo[i]) ki += a[i] - oo[i]; } res = min(res, ki); } cout << res << endl; return 0; }