結果

問題 No.929 よくあるボールを移動するやつ
ユーザー sash2104sash2104
提出日時 2019-11-22 22:06:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 749 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 69,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 11:33:46
合計ジャッジ時間 1,151 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 15 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> lb(n);
  for (int &b: lb) cin >> b;

  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < n-1; ++i) {
    cnt += lb[i];
    // cout << i << " " << lb[i] << " " << cnt << endl;
    if (cnt > i+1) {
      assert(lb[i] > 1);
      int diff = cnt-(i+1);
      lb[i+1] += diff;
      lb[i] -= diff;
      ans += diff;
      cnt -= diff;
    }
  }
  cnt = 0;
  for (int i = n-1; i > 0; --i) {
    cnt += lb[i];
    if (cnt > n-i) {
      assert(lb[i] > 1);
      int diff = cnt-(n-i);
      lb[i-1] += diff;
      lb[i] -= diff;
      assert(lb[i] == 1);
      ans += diff;
      cnt -= diff;
    }
  }
  cout << ans << endl;
}

0