結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
kei
|
| 提出日時 | 2018-04-26 23:23:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,341 bytes |
| コンパイル時間 | 1,526 ms |
| コンパイル使用メモリ | 168,532 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 21:16:04 |
| 合計ジャッジ時間 | 2,538 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 2 WA * 18 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
/*
<url:https://yukicoder.me/problems/no/77>
問題文============================================================
Vegaはレンガで平面ピラミッドを作りたいと考えてる。
庭には、すでにN列分のレンガが隙間なく積まれていて、それぞれのi列目の積まれている個数はAiで表される。
最初の配置から、レンガをいくつか動かして、ピラミッドの配置になるように並び替えたいです。
ピラミッドの配置とは、1から始めて[1,2,3,4,3,2,1]のように中心の位置まで1ずつ増え、中心以降は1ずつ減るような配置である。
(つまり、ピラミッド配置の列数は奇数になる。)
ピラミッドとは別の場所に、捨て置き場も設けられており、ピラミッドの配置に使われなかったレンガを置くこともできる。
移動とは、任意の列の一番上にある1つのレンガを持ち、別の列に移動するか、もしくは捨て置き場に移動することである。
このとき、ピラミッド配置は、最初の配置の1列目のレンガの場所から始めるとする。
与えられた列数よりか大きい列になる場合がある。
最初の配置から0個以上のレンガを移動しできるピラミッド配置への最小の移動数を求めてください。
ビラミッドの場所には1つのピラミッドのみがあるとして、不要なレンガはすべて捨て置き場に移動するとする。
レンガはどれも同じサイズの立方体であるとする。
=================================================================
解説=============================================================
================================================================
*/
ll solve(){
ll res = LINF;
ll N; cin >> N;
vector<ll> A(N); for(auto& in:A) cin >> in;
ll sum = accumulate(A.begin(),A.end(),0LL);
for(int i = 0; i < N;i++){
for(int j = 0; i + 2*j < N;j++){
if((j+1)*(j+1) > sum) break;
// cout << min((j+1)*(j+1),accumulate(A.begin()+i,A.begin()+i+2*j+1,0)) << endl;
res = min(res,sum - min((j+1)*(j+1),accumulate(A.begin()+i,A.begin()+i+2*j+1,0)));
}
}
return res;
}
int main(void) {
cin.tie(0); ios_base::sync_with_stdio(false);
cout << solve() << endl;
return 0;
}
kei