結果

問題 No.1077 Noelちゃんと星々4
ユーザー chocono2230chocono2230
提出日時 2020-06-12 22:20:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 167,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 10:37:36
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 25 ms
4,380 KB
testcase_03 AC 33 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 30 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 33 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void ss(vector<int> &sums, vector<int> &y, vector<int> &yy){
  int n = y.size();
  rrep(i, n){
    int ad;
    if(y.at(i) < yy.at(i)) ad = 1;
    else if(y.at(i) == yy.at(i)) ad = 0;
    else ad = -1;
    sums.at(i) = sums.at(i+1) + ad;
  }
}

int main(){
  int n;
  cin >> n;
  vector<int> y(n);
  rep(snip_i, n) cin >> y.at(snip_i);
  vector<int> sums(n+1, 0);
  vector<int> yy(n, 1e4);
  vector<int> ans(n);
  rep(i, n){
    ans.at(i) = yy.at(i) - y.at(i);
  }
  int r = n;

  while(r > 0){
    ss(sums, y, yy);
    rep(i, r){
      int d = yy.at(i) - y.at(i);
      if(d > 0){
        yy.at(i)--;
        continue;
      }
      // int cost = -1;
      // rep2(j, i+1, r){
      //   if(yy.at(j) - y.at(j) > 0) cost++;
      //   else if(yy.at(j) - y.at(j) == 0){
      //   }else cost--;
      //   if(cost > 0) break;
      // }
      int cost = sums.at(i);
      if(cost > 0) yy.at(i)--;
      else{
        r = i;
        break;
      }
    }
  }
  int aa = 0;
  rep(i, n){
    // cerr << yy.at(i) << " ";
    aa += abs(yy.at(i) - y.at(i));
  }
  // cerr << endl;
  cout << aa << endl;
  return 0;
}
0