結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー | totori_nyaa |
提出日時 | 2020-06-12 21:40:51 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 2,038 ms |
コンパイル使用メモリ | 199,204 KB |
実行使用メモリ | 42,384 KB |
最終ジャッジ日時 | 2023-09-06 09:59:05 |
合計ジャッジ時間 | 3,601 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 37 ms
32,240 KB |
testcase_03 | AC | 47 ms
38,240 KB |
testcase_04 | AC | 16 ms
15,792 KB |
testcase_05 | AC | 13 ms
11,524 KB |
testcase_06 | AC | 21 ms
17,704 KB |
testcase_07 | AC | 23 ms
19,804 KB |
testcase_08 | AC | 18 ms
15,712 KB |
testcase_09 | AC | 15 ms
13,544 KB |
testcase_10 | AC | 48 ms
38,240 KB |
testcase_11 | AC | 31 ms
25,828 KB |
testcase_12 | AC | 27 ms
23,776 KB |
testcase_13 | AC | 12 ms
11,532 KB |
testcase_14 | AC | 47 ms
38,240 KB |
testcase_15 | AC | 26 ms
22,000 KB |
testcase_16 | AC | 18 ms
15,648 KB |
testcase_17 | AC | 29 ms
24,004 KB |
testcase_18 | AC | 48 ms
40,244 KB |
testcase_19 | AC | 12 ms
11,456 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 53 ms
42,384 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); int dp[1001][10001]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int ans = 1e9; int ma = 10001; for(int i=1;i<=n;i++){ for(int j=0;j<ma;j++){ dp[i][j] = 1e9; } } for(int i=0;i<n;i++){ for(int j=0;j<ma;j++){ if(j<=a[i])chmin(dp[i+1][a[i]],dp[i][j]); chmin(dp[i+1][j],dp[i][j]+abs(j-a[i])); } for(int j=1;j<ma;j++){ chmin(dp[i+1][j],dp[i+1][j-1]); } } for(int i=0;i<ma;i++)chmin(ans,dp[n][i]); cout << ans << endl; }