結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
kongarishisyamo
|
| 提出日時 | 2016-02-29 02:46:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 754 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 56,824 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 12:38:25 |
| 合計ジャッジ時間 | 1,339 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
#include<iostream>
using namespace std;
#define NMAX 100
int main(){
int N;
int A[NMAX*4+1]={0};
int sum[NMAX*4+1]={0};
int suma=0;
int ans=-1;
int locd,loca;
cin>>N;
for(int i=1;i<=NMAX*4;i+=2){
int c=1;
for(int j=0;j<i;j++){
sum[i]+=c;
if(i/2+1>j+1) c++;
else c--;
}
}
for(int i=1;i<=N;i++){
cin>>A[i];
suma+=A[i];
}
for(int i=1;;i+=2){
if(sum[i]>suma) break;
locd=0;
loca=0;
int c=1;
for(int j=1;j<=i;j++){
if(c>A[j]) loca+=c-A[j];
else if(c<A[j]) locd+=A[j]-c;
if(i/2+1>j) c++;
else c--;
}
for(int j=i+1;j<=N;j++){
locd+=A[j];
}
/*cout<<sum[i]<<","<<c<<":"<<i<<","<<loca<<","<<locd<<endl;*/
if(loca>locd) continue;
if(ans==-1||locd<ans) ans=locd;
}
cout<<ans<<endl;
}
kongarishisyamo