結果

問題 No.1826 Fruits Collecting
ユーザー 👑 ygussanyygussany
提出日時 2022-01-28 22:54:28
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,934 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 31,188 KB
実行使用メモリ 15,588 KB
最終ジャッジ日時 2023-08-28 21:30:55
合計ジャッジ時間 5,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
8,072 KB
testcase_26 AC 2 ms
8,068 KB
testcase_27 AC 2 ms
8,076 KB
testcase_28 AC 2 ms
10,028 KB
testcase_29 AC 3 ms
9,984 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
10,108 KB
testcase_44 AC 3 ms
10,040 KB
testcase_45 AC 3 ms
8,072 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, int 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