結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-06-12 21:45:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,373 bytes |
コンパイル時間 | 2,748 ms |
コンパイル使用メモリ | 192,000 KB |
最終ジャッジ日時 | 2025-01-11 02:24:35 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:32:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | rep(i, n) scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))#define rep(i, n) For((i), 0, (n))#define rrep(i, n) rFor((i), (n), 0)#define fi first#define se secondusing namespace std;typedef long long lint;typedef unsigned long long ulint;typedef pair<int, int> pii;typedef pair<lint, lint> pll;template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}template<class T> T div_floor(T a, T b){if(b < 0) a *= -1, b *= -1;return a>=0 ? a/b : (a+1)/b-1;}template<class T> T div_ceil(T a, T b){if(b < 0) a *= -1, b *= -1;return a>0 ? (a-1)/b+1 : a/b;}constexpr lint mod = 1e9+7;constexpr lint INF = mod * mod;constexpr int MAX = 10010;int main(){int n;scanf("%d", &n);int a[n];rep(i, n) scanf("%d", &a[i]);int dp[2][MAX];rep(i, 2)rep(j, MAX) dp[i][j] = mod;rep(j, MAX) dp[0][j] = 0;rep(i, n){rep(j, MAX)if(dp[0][j] < mod){chmin(dp[1][j], dp[0][j] + abs(j - a[i]));}rep(j, MAX){dp[0][j] = dp[1][j];dp[1][j] = mod;if(j > 0) chmin(dp[0][j], dp[0][j-1]);}}printf("%d\n", dp[0][MAX-1]);}