結果
問題 | No.77 レンガのピラミッド |
ユーザー |
![]() |
提出日時 | 2017-06-28 22:55:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,033 bytes |
コンパイル時間 | 800 ms |
コンパイル使用メモリ | 90,436 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 15:01:55 |
合計ジャッジ時間 | 1,241 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main(){ int n; cin >> n; int A[500]; FOR (i,0,500) A[i] = 0; int sum_A = 0; FOR (i,0,n) { cin >> A[i]; sum_A += A[i]; } int B[500]; FOR (i,0,500) B[i] = 0; int ans = 999999; FOR (i,0,250) { int num = 2 * i + 1; int b = 1; int sum_B = 0; FOR (j,0,num) { B[j] = b; sum_B += b; if(j>=num/2) b--; else b++; } if(sum_B > sum_A) break; int cnt = 0; FOR (j,0,500) { cnt += abs(A[j] - B[j]); } if (sum_A > sum_B) { cnt -= sum_A - sum_B; cnt /= 2; cnt += sum_A - sum_B; } else { cnt /= 2; } ans = min(ans, cnt); } cout << ans << endl; return 0; }