結果

問題 No.1077 Noelちゃんと星々4
ユーザー kkktymkkktym
提出日時 2020-06-12 22:02:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 78,408 KB
実行使用メモリ 42,108 KB
最終ジャッジ日時 2023-09-06 10:28:13
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 38 ms
29,916 KB
testcase_03 AC 48 ms
38,016 KB
testcase_04 AC 15 ms
13,652 KB
testcase_05 AC 11 ms
10,960 KB
testcase_06 AC 20 ms
16,632 KB
testcase_07 AC 22 ms
18,552 KB
testcase_08 AC 17 ms
14,472 KB
testcase_09 AC 14 ms
12,776 KB
testcase_10 AC 47 ms
37,708 KB
testcase_11 AC 31 ms
25,432 KB
testcase_12 AC 26 ms
21,600 KB
testcase_13 AC 11 ms
10,396 KB
testcase_14 AC 46 ms
37,088 KB
testcase_15 AC 25 ms
21,060 KB
testcase_16 AC 17 ms
14,676 KB
testcase_17 AC 29 ms
23,388 KB
testcase_18 AC 49 ms
38,524 KB
testcase_19 AC 11 ms
10,096 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 53 ms
42,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  vector<int> a(n);
  int maxi = 0;
  rep(i,n) {
    cin >> a[i];
    chmax(maxi, a[i]);
  }

  vector<vector<int>> sum(n+1, vector<int>(maxi + 1, 1e+9));
  rep(i,maxi+1) sum[0][i] = 0;
  rep1(i,n) {
    rep(j,maxi+1) {
      if(j > 0) sum[i][j] = min(sum[i][j-1], sum[i-1][j] + abs(a[i-1] - j));
      else sum[i][j] = sum[i-1][j] + abs(a[i-1] - j);
    }
  }
  cout << sum[n][maxi] << "\n";

  
  return 0;
}
0