結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2015-06-07 21:43:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,011 bytes |
コンパイル時間 | 495 ms |
コンパイル使用メモリ | 71,872 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 14:36:36 |
合計ジャッジ時間 | 1,187 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <iostream> #include <algorithm> #include <functional> #include <string> #include <climits> #include <vector> #include <numeric> #include <complex> using namespace std; #define long __int64 //#define __int64 long long #define REP(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) REP(i,0,n) const int Vecy[4] = {0,-1,0,1}; const int Vecx[4] = {1,0,-1,0}; int main(){ int n; int from[199] = {0}; int to[199] = {0};//1,4,9,16... int sum = 0; int weight; int check; int plus = 0; int minus = 0; cin >> n; rep(i,n){ cin >> from[i]; sum += from[i]; } check = 4; weight = 1; while(sum >= check){ weight += 2; check += weight + 2; } for(int i=0; i<=weight/2; i++){ to[i] = i + 1; to[weight-i-1] = i + 1; } for(int i=0; i<n; i++){ //cout << to[i] << " - " << from[i] << " = " << to[i] - from[i] << endl; if(from[i] < to[i]){ plus += to[i] - from[i]; }else if(from[i] > to[i]){ minus += from[i] - to[i]; } } cout << max(plus, minus) << endl; return 0; }