結果
| 問題 | No.838 Noelちゃんと星々3 |
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2019-08-05 17:19:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 745 bytes |
| コンパイル時間 | 1,595 ms |
| コンパイル使用メモリ | 173,500 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 13:38:12 |
| 合計ジャッジ時間 | 3,375 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
const ll INF=1LL<<50;
int main(){
int N;cin>>N;
vector<ll> A(N);
for(int i=0;i<N;i++){
cin>>A[i];
}
sort(all(A));
ll dp[N+1][2];//j=0のときは2個区切りj=1のときは3個区切り
for(int i=0;i<N+1;i++){
for(int j=0;j<2;j++){
dp[i][j]=INF;
}
}
dp[0][0]=dp[0][1]=0;
dp[2][0]=A[1]-A[0];
for(int i=3;i<=N;i++){
dp[i][0]=min(dp[i-2][0],dp[i-2][1])+A[i-1]-A[i-2];
dp[i][1]=min(dp[i-3][0],dp[i-3][1])+A[i-1]-A[i-3];
}
cout<<min(dp[N][0],dp[N][1])<<endl;
}
Rubikun