結果

問題 No.77 レンガのピラミッド
ユーザー nanasilinanasili
提出日時 2014-11-26 00:15:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 74,748 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-31 01:18:38
合計ジャッジ時間 1,579 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;


int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int total = 0;
  for (int i = 0; i < n; i++) total += a[i];
  int ans = 1000000000;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i%2 == 0) continue;
    cnt++;
    if (total < cnt*cnt) continue;

    for (int bias = 0; bias <= n-i; bias++) {
      int k = 0, s = 0;
      for (int j = 0; j < i/2; j++) {
        if (a[j+bias] > j+1) {
          k += a[j+bias]-(j+1);
        }else {
          s += j+1-a[j+bias];
        }
      }
      for (int j = i/2, l = i/2; j < i; j++,l--) {
        if (a[j+bias] > l+1) {
          k += a[j+bias]-(l+1);
        }else {
          s += l+1-a[j+bias];
        }
      }
      for (int j = 0; j < bias; j++) k += a[j];
      for (int j = i+bias; j < n; j++) k += a[j];

      ans = min(k, ans);
      // cout << sum << " " << i << endl;
    }
  }

  cout << ans << endl;
}
0