結果
問題 | No.77 レンガのピラミッド |
ユーザー |
|
提出日時 | 2015-02-22 00:49:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 62,304 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 21:49:02 |
合計ジャッジ時間 | 1,330 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> using namespace std; int main() { int n; cin >> n; vector<int> a(2 * n - 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> b(2 * n - 1, 0); int ans = 1e9; for (int center = 0; center < n; center++) { fill(b.begin(), b.end(), 0); int i; for (i = 0; i <= center; i++) { b[i] = i + 1; } for ( ; b[i - 1] > 0; i++) { b[i] = b[i - 1] - 1; } int more = 0; int less = 0; for (int j = 0; j < a.size(); j++) { int diff = a[j] - b[j]; if (diff > 0) { more += diff; } else { less += -diff; } } if (more >= less) { ans = min(ans, more); } } cout << ans << endl; return 0; }