結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2015-06-29 06:12:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 790 ms |
コンパイル使用メモリ | 84,184 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 21:08:53 |
合計ジャッジ時間 | 1,779 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#define _USE_MATH_DEFINES #include <iostream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <list> #include <queue> #include <vector> #include <complex> #include <set> ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)<<endl; ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(6);// int N; cin>>N; int A[200]; int Amax=0; rep(i,N){ cin>>A[i]; Amax += A[i]; } for(int i=N;i<200;++i){ A[i] = 0; } /////// //N^2 int ans = -1; int tans; int ooi=0; int suk=0; int use=0; for(int i=0;i*i<=Amax;++i){ tans = 0; ooi=0; suk=0; use=0; for(int k = 1; k <= 2*i-1 ;++k){ use +=A[k-1]; if ( k <= i){ if( A[k-1]>k){ ooi += A[k-1]-k; } else{ suk += k-A[k-1]; } }else{//2*i-k if( A[k-1]>2*i-k){ ooi += A[k-1] -(2*i-k); } else{ suk += (2*i-k) - A[k-1]; } } } if( suk > ooi){ tans = suk; suk = suk-ooi; }else{ tans = ooi; suk = 0; } //残り tans += Amax - use - suk; if(ans == -1 || ans > tans){ ans = tans; } } P(ans); return 0; }