結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー | hedwig100 |
提出日時 | 2020-06-12 21:50:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 166 ms / 2,000 ms |
コード長 | 1,067 bytes |
コンパイル時間 | 1,632 ms |
コンパイル使用メモリ | 170,452 KB |
実行使用メモリ | 163,616 KB |
最終ジャッジ日時 | 2023-09-06 10:14:06 |
合計ジャッジ時間 | 4,174 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,376 KB |
testcase_01 | AC | 4 ms
4,912 KB |
testcase_02 | AC | 115 ms
113,064 KB |
testcase_03 | AC | 152 ms
145,568 KB |
testcase_04 | AC | 45 ms
45,868 KB |
testcase_05 | AC | 34 ms
35,200 KB |
testcase_06 | AC | 59 ms
58,848 KB |
testcase_07 | AC | 69 ms
67,520 KB |
testcase_08 | AC | 49 ms
49,772 KB |
testcase_09 | AC | 43 ms
43,116 KB |
testcase_10 | AC | 149 ms
145,604 KB |
testcase_11 | AC | 97 ms
95,180 KB |
testcase_12 | AC | 80 ms
78,928 KB |
testcase_13 | AC | 33 ms
33,608 KB |
testcase_14 | AC | 145 ms
142,320 KB |
testcase_15 | AC | 77 ms
76,388 KB |
testcase_16 | AC | 51 ms
51,088 KB |
testcase_17 | AC | 87 ms
86,504 KB |
testcase_18 | AC | 150 ms
148,232 KB |
testcase_19 | AC | 32 ms
32,108 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | AC | 166 ms
163,616 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; constexpr int H = 20000; int main() { int N; cin >> N; vector<ll> Y(N); rep(i,N) cin >> Y[i]; vector<vector<ll>> dp(N + 1,vector<ll>(H,INF)); rep(i,N) { if (i == 0) { rep(j,H) { if (j == 0) dp[i + 1][j] = abs(j - Y[i]); else dp[i + 1][j] = min(dp[i + 1][j - 1],abs(j - Y[i])); } } else { rep(j,H) { if (j == 0) dp[i + 1][j] = dp[i][j] + abs(j - Y[i]); else dp[i + 1][j] = min(dp[i + 1][j - 1],dp[i][j] + abs(j - Y[i])); } } } ll ans = HINF; rep(i,H) { ans = min(ans,dp[N][i]); } cout << ans << endl; return 0; }