結果

問題 No.77 レンガのピラミッド
ユーザー nenuonnenuon
提出日時 2017-06-28 22:53:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,032 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 90,392 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 04:10:17
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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[100];
  FOR (i,0,100) A[i] = 0;
  int sum_A = 0;
  FOR (i,0,n) {
    cin >> A[i];
    sum_A += A[i];
  }
  int B[100];
  FOR (i,0,100) B[i] = 0;
  int ans = 999999;
  FOR (i,0,50) {
    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,100) {
      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;
}
0