結果
問題 |
No.838 Noelちゃんと星々3
|
ユーザー |
|
提出日時 | 2020-06-01 14:44:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 541 bytes |
コンパイル時間 | 2,418 ms |
コンパイル使用メモリ | 196,852 KB |
最終ジャッジ日時 | 2025-01-10 20:16:51 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | rep(i,n) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; const long long INF=1LL<<61; int main(){ int n; scanf("%d",&n); vector<lint> a(n); rep(i,n) scanf("%lld",&a[i]); sort(a.begin(),a.end()); if(n==2) return printf("%lld\n",a[1]-a[0]),0; if(n==3) return printf("%lld\n",a[2]-a[0]),0; vector<lint> dp(n); dp[0]=INF; dp[1]=a[1]-a[0]; dp[2]=a[2]-a[0]; for(int i=3;i<n;i++){ dp[i]=min(dp[i-2]+a[i]-a[i-1],dp[i-3]+a[i]-a[i-2]); } printf("%lld\n",dp[n-1]); return 0; }