結果

問題 No.838 Noelちゃんと星々3
ユーザー bal4ubal4u
提出日時 2019-09-07 10:33:22
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 28,936 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:27:30
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: 838 Noelちゃんと星々3
// 2019.9.7 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

//// 高速入力
#if 1
int getchar_unlocked(void);
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {  // 整数の入力(負数対応)
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int y[100005]; int N;
int dp[100005];

void Qsort(int *a, int l, int r) {
	int i, j, m, t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
		while (a[i] < m) i++;
		while (m < a[j]) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

inline static int MIN(int a, int b) { return a < b? a: b; }

int main()
{
	int i;
	
	N = in();
	for (i = 0; i < N; i++) y[i] = in();
	Qsort(y, 0, N-1);
	dp[0] = y[N-1]+1, dp[1] = y[1]-y[0], dp[2] = y[2]-y[0];
	for (i = 3; i < N; i++)
		dp[i] = MIN(dp[i-2]+y[i]-y[i-1], dp[i-3]+y[i]-y[i-2]);
	printf("%d\n", dp[N-1]);
	return 0;
}
0