結果

問題 No.838 Noelちゃんと星々3
ユーザー LayCurseLayCurse
提出日時 2019-06-14 21:42:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,937 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 202,156 KB
実行使用メモリ 4,924 KB
最終ジャッジ日時 2023-08-08 17:43:12
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,884 KB
testcase_01 AC 15 ms
4,880 KB
testcase_02 AC 14 ms
4,920 KB
testcase_03 AC 15 ms
4,924 KB
testcase_04 AC 14 ms
4,916 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
long long Y[100000];
long long dp[100001];
int main(){
  int i, j, k;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(Y[Lj4PdHRW]);
    }
  }
  sort(Y, Y+N);
  for(i=0;i<N+1;i++){
    dp[i] = 4611686016279904256LL;
  }
  dp[0] = 0;
  for(i=0;i<N;i++){
    if(i+2 <= N){
      chmin(dp[i+2], dp[i] + Y[i+1]-Y[i]);
    }
    if(i+3 <= N){
      chmin(dp[i+3], dp[i] + Y[i+2]-Y[i]);
    }
  }
  wt_L(dp[N]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190609-2 [beta]

// --- original code ---
// int N; ll Y[1d5];
// ll dp[100001];
// {
//   int i, j, k;
//   rd(N,Y(N));
// 
//   sort(Y, Y+N);
// 
//   rep(i,N+1) dp[i] = ll_inf;
//   dp[0] = 0;
// 
//   rep(i,N){
//     if(i+2 <= N) dp[i+2] <?= dp[i] + Y[i+1]-Y[i];
//     if(i+3 <= N) dp[i+3] <?= dp[i] + Y[i+2]-Y[i];
//   }
// 
//   wt(dp[N]);
// }
0