結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-28 17:26:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,634 bytes |
| コンパイル時間 | 885 ms |
| コンパイル使用メモリ | 64,364 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 00:18:46 |
| 合計ジャッジ時間 | 2,006 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 13 WA * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <math.h>
#define MAX_N 100
using namespace std;
int piramidd(int x,int n){
//n段のピラミッド列を構成するとして、x番目の段数を返す
if(x > n){
return n - (x-n);
}else{
return x;
}
}
int main(){
int n;
int total = 0;
int min = 99999999;
int tmp = 0,tmp2 = 0;
vector<int> A(100,0);
cin >> n;
for(int d =0;d <n;d++){
cin >> A[d];
total += A[d];
}
int max_h = sqrt(total);
// cout <<"max:" << max_h << " " <<"total:"<< total << endl;
if(max_h > n){
//cout <<"change:"<< n << endl;
max_h = n;
}
//sqrt(total) ~ 1段まで ピラミッドを構成してみる。
for(int d = max_h; d > 0; d--){
if(total == max_h*max_h||true ){
for(int e = 0; e <= 2*d-2;e++){
if( A[e]-piramidd(e+1,d)>0) tmp+= A[e]-piramidd(e+1,d);
else tmp2 += (piramidd(e+1,d)- A[e]);
// cout << "A[e]:"<< A[e] << " | " << "pi(e,d)" << piramidd(e+1,d) << " " << A[e]-piramidd(e+1,d) << endl;
}
// cout << "tmp2:" << tmp2 << endl;
}else{
//ゴミ捨て場に移す必要がある
for(int e = 1; e <= 2*d-1;e++){
if( A[e]-piramidd(e,d)>0) tmp+= A[e]-piramidd(e,d);
cout << A[e]-piramidd(e,d) << endl;
}
}
if(tmp2 > tmp){ tmp = tmp2;}
if(min > tmp){
min = tmp;
}
//cout << "test^^"<< endl;
}
cout << min << endl;
return 0;
}