結果

問題 No.497 入れ子の箱
ユーザー bal4ubal4u
提出日時 2019-07-14 18:27:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 2,094 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 30,412 KB
実行使用メモリ 42,324 KB
最終ジャッジ日時 2023-08-16 03:12:15
合計ジャッジ時間 3,112 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 44 ms
42,324 KB
testcase_05 AC 44 ms
42,116 KB
testcase_06 AC 44 ms
42,300 KB
testcase_07 AC 41 ms
40,824 KB
testcase_08 AC 42 ms
40,804 KB
testcase_09 AC 44 ms
40,840 KB
testcase_10 AC 44 ms
40,904 KB
testcase_11 AC 41 ms
40,900 KB
testcase_12 AC 39 ms
36,576 KB
testcase_13 AC 38 ms
36,392 KB
testcase_14 AC 38 ms
36,500 KB
testcase_15 AC 38 ms
36,408 KB
testcase_16 AC 41 ms
36,988 KB
testcase_17 AC 40 ms
36,376 KB
testcase_18 AC 41 ms
39,384 KB
testcase_19 AC 41 ms
39,920 KB
testcase_20 AC 43 ms
39,840 KB
testcase_21 AC 43 ms
39,908 KB
testcase_22 AC 42 ms
39,248 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,376 KB
testcase_27 AC 42 ms
37,884 KB
testcase_28 AC 41 ms
38,184 KB
testcase_29 AC 40 ms
38,212 KB
testcase_30 AC 35 ms
34,572 KB
testcase_31 AC 37 ms
35,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.497 入れ子の箱
// 2019.7.14 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

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

#define MAX 1005
#define CMAX 100000000
typedef struct { int x, y, z, id; } T;
T t[MAX+5], s[MAX+5]; int N;
int dp[MAX+5];
int c[2][CMAX+5];

void update(int f, int x, int v) {
	while (x <= CMAX) {
		if (c[f][x] < v) c[f][x] = v;
		x += x & (-x);
	}
}

int getmax(int f, int x) {
	int a = 0;
	while (x > 0) {
		if (a < c[f][x]) a = c[f][x];
		x -= x & (-x);
	}
	return a;
}

void clear(int f, int x) {
	while (x <= CMAX) {
		c[f][x] = 0;
		x += x & (-x);
	}
}

int cmp(const void *a, const void *b) { return ((T *)a)->x - ((T *)b)->x; }
int cmp2(const void *a, const void *b) {
	int t = ((T *)a)->y - ((T *)b)->y; if (t) return t;
	return ((T *)b)->z - ((T *)a)->z;
}

void cdq(int l, int r) {
	int i, k, a, tx, m;

	if (l == r) { if (dp[l] == 0) dp[l] = 1; return; }
	m = (l + r) >> 1;
	tx = t[m + 1].x;
	cdq(l, m);
	k = 0; for (i = l; i <= r; i++) s[k] = t[i], s[k++].id = i;
	qsort(s, k, sizeof(T), cmp2);
	for (i = 0; i < k; i++) {
		if (s[i].id <= m) {
			update(1, s[i].z, dp[s[i].id]);
			if (s[i].x != tx) update(0, s[i].z, dp[s[i].id]);
		} else {
			if (s[i].x == tx) a = getmax(0, s[i].z - 1);
			else a = getmax(1, s[i].z - 1);
			if (dp[s[i].id] < a + 1) dp[s[i].id] = a + 1;
		}
	}
	for (i = 0; i < k; i++) {
		if (s[i].id <= m) {
			clear(1, s[i].z);
			if (s[i].x != tx) clear(0, s[i].z);
		}
	}
	cdq(m + 1, r);
}

int main()
{
	int i, ans;

	N = in(); for (i = 1; i <= N; i++) {
		int tmp, x = in(), y = in(), z = in();
		if (x > y) tmp = x, x = y, y = tmp;
		if (y > z) {
			tmp = y, y = z, z = tmp;
			if (x > y) tmp = x, x = y, y = tmp;
		}
		t[i].x = x, t[i].y = y, t[i].z = z;
	}
	qsort(t+1, N, sizeof(T), cmp);
	
	if (t[1].x == t[N].x) ans = 1;
	else {
		cdq(1, N);
		ans = 0; for (i = 1; i <= N; i++) if (dp[i] > ans) ans = dp[i];
	}
	printf("%d\n", ans);
	return 0;
}
0