結果
| 問題 |
No.1077 Noelちゃんと星々4
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2020-06-12 21:50:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,658 bytes |
| コンパイル時間 | 747 ms |
| コンパイル使用メモリ | 82,624 KB |
| 実行使用メモリ | 18,896 KB |
| 最終ジャッジ日時 | 2024-06-24 04:50:18 |
| 合計ジャッジ時間 | 1,615 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 20 |
ソースコード
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
ll dp[1005][1005];
ll sdp[1005][1005];
void solve()
{
int n;
scanf("%d", &n);
vector<int> a(n);
int i, j;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= n; j++) {
dp[i][j] = LINF;
}
}
for (j = 0; j <= 1000; j++) {
dp[0][j] = abs(j - a[0]);
if (j > 0) sdp[0][j] = MIN(sdp[0][j - 1], dp[0][j]);
else sdp[0][j] = dp[0][j];
}
for (i = 1; i < n; i++) {
for (j = 0; j <= 1000; j++) {
dp[i][j] = sdp[i - 1][j] + abs(j - a[i]);
if (j > 0) sdp[i][j] = MIN(sdp[i][j - 1], dp[i][j]);
else sdp[i][j] = dp[i][j];
}
}
printf("%lld\n", sdp[n - 1][1000]);
return;
}
int main(int argc, char* argv[])
{
#if 1
solve();
#else
int T;
scanf("%d", &T);
int t;
for(t=0; t<T; t++) {
//printf("Case #%d: ", t+1);
solve();
}
#endif
return 0;
}
tarattata1