結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             しの
                         | 
                    
| 提出日時 | 2020-05-05 21:41:48 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 68 ms / 2,000 ms | 
| コード長 | 524 bytes | 
| コンパイル時間 | 2,865 ms | 
| コンパイル使用メモリ | 191,032 KB | 
| 最終ジャッジ日時 | 2025-01-10 07:03:09 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:14:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   for (int i = 0; i < n; i++) scanf("%d", y+i);
      |                               ~~~~~^~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MaxN = 1005;
const int MaxY = 10005;
int dp[MaxN][MaxY];
int y[MaxY];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", y+i);
  fill(dp[0], dp[MaxN], INF);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < MaxY-1; j++) dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
    for (int j = 0; j < MaxY; j++) dp[i+1][j] = dp[i][j] + abs(j-y[i]);
  }
  printf("%d\n", *min_element(dp[n], dp[n+1]));
}
            
            
            
        
            
しの