結果
| 問題 |
No.497 入れ子の箱
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-14 18:27:59 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 5,000 ms |
| コード長 | 2,094 bytes |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 32,128 KB |
| 実行使用メモリ | 42,368 KB |
| 最終ジャッジ日時 | 2024-11-24 12:44:22 |
| 合計ジャッジ時間 | 2,280 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:14:24: note: in expansion of macro 'gc'
14 | int n = 0, c = gc();
| ^~
ソースコード
// 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;
}
bal4u