結果

問題 No.1826 Fruits Collecting
ユーザー 👑 ygussanyygussany
提出日時 2022-01-28 22:57:11
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,940 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 30,832 KB
実行使用メモリ 15,612 KB
最終ジャッジ日時 2023-08-28 21:34:26
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,048 KB
testcase_01 AC 3 ms
9,992 KB
testcase_02 AC 3 ms
8,020 KB
testcase_03 AC 3 ms
10,072 KB
testcase_04 AC 2 ms
7,880 KB
testcase_05 AC 52 ms
11,004 KB
testcase_06 AC 86 ms
13,444 KB
testcase_07 AC 62 ms
11,344 KB
testcase_08 AC 9 ms
8,008 KB
testcase_09 AC 85 ms
13,284 KB
testcase_10 AC 58 ms
11,076 KB
testcase_11 AC 56 ms
10,724 KB
testcase_12 AC 23 ms
10,432 KB
testcase_13 AC 13 ms
10,180 KB
testcase_14 AC 19 ms
8,372 KB
testcase_15 AC 130 ms
12,720 KB
testcase_16 AC 130 ms
12,848 KB
testcase_17 AC 130 ms
12,736 KB
testcase_18 AC 130 ms
12,812 KB
testcase_19 AC 131 ms
12,864 KB
testcase_20 AC 130 ms
14,036 KB
testcase_21 AC 131 ms
13,924 KB
testcase_22 AC 130 ms
13,736 KB
testcase_23 AC 130 ms
13,984 KB
testcase_24 AC 130 ms
14,048 KB
testcase_25 AC 2 ms
10,012 KB
testcase_26 AC 2 ms
9,924 KB
testcase_27 AC 2 ms
10,028 KB
testcase_28 AC 2 ms
9,976 KB
testcase_29 AC 2 ms
10,036 KB
testcase_30 AC 25 ms
10,368 KB
testcase_31 AC 48 ms
12,588 KB
testcase_32 AC 39 ms
10,876 KB
testcase_33 AC 130 ms
14,264 KB
testcase_34 AC 108 ms
13,520 KB
testcase_35 AC 26 ms
8,832 KB
testcase_36 AC 127 ms
14,100 KB
testcase_37 AC 90 ms
14,156 KB
testcase_38 AC 64 ms
13,836 KB
testcase_39 AC 75 ms
14,644 KB
testcase_40 AC 96 ms
15,612 KB
testcase_41 AC 22 ms
9,008 KB
testcase_42 AC 5 ms
10,148 KB
testcase_43 AC 2 ms
8,056 KB
testcase_44 AC 2 ms
7,940 KB
testcase_45 AC 2 ms
8,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef struct {
	long long key;
	int id;
} data;

void merge_sort(int n, data x[])
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

void chmax(long long* a, long long b)
{
	if (*a < b) *a = b;
}

void update_BIT(int N, long long BIT[], int i, long long k)
{
	while (i <= N) {
		chmax(&(BIT[i]), k);
		i += (i & -i);
	}
}

long long max_BIT(long long BIT[], int r)
{
	long long max = 0;
	while (r > 0) {
		chmax(&max, BIT[r]);
		r -= (r & -r);
	}
	return max;
}

int main()
{
	int i, N, T[200001], Z[200001], V[200001], X[200001], Y[200001];
	data d[2][200001];
	scanf("%d", &N);
	for (i = 1, X[0] = 0, Y[0] = 0, d[0][0].key = 0, d[0][0].id = 0, d[1][0].key = 0, d[1][0].id = 0; i <= N; i++) {
		scanf("%d %d %d", &(T[i]), &(Z[i]), &(V[i]));
		if (abs(Z[i]) > T[i]) {
			i--;
			N--;
			continue;
		}
		X[i] = T[i] + Z[i];
		Y[i] = T[i] - Z[i];
		d[0][i].key = X[i];
		d[0][i].id = i;
		d[1][i].key = Y[i];
		d[1][i].id = i;
	}
	merge_sort(N + 1, d[0]);
	merge_sort(N + 1, d[1]);
	
	int j, n, m, x[200003], y[200003];
	for (i = 0, n = 0; i <= N; i = j) {
		x[++n] = d[0][i].key;
		for (j = i; j <= N && d[0][j].key == x[n]; j++) X[d[0][j].id] = n;
	}
	for (i = 0, m = 0; i <= N; i = j) {
		y[++m] = d[1][i].key;
		for (j = i; j <= N && d[1][j].key == y[m]; j++) Y[d[1][j].id] = m;
	}
	
	long long BIT[200003] = {};
	for (i = 1; i <= N; i++) {
		d[0][i-1].key = ((long long)X[i] << 20) + Y[i];
		d[0][i-1].id = i;
	}
	merge_sort(N, d[0]);
	for (i = 0; i < N; i++) {
		j = d[0][i].id;
		update_BIT(m, BIT, Y[j], max_BIT(BIT, Y[j]) + V[j]);
	}
	printf("%lld\n", max_BIT(BIT, m));
	fflush(stdout);
	return 0;
}
0