結果
| 問題 | No.777 再帰的ケーキ | 
| コンテスト | |
| ユーザー |  akakimidori | 
| 提出日時 | 2019-05-19 05:06:28 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 165 ms / 2,000 ms | 
| コード長 | 1,781 bytes | 
| コンパイル時間 | 156 ms | 
| コンパイル使用メモリ | 32,000 KB | 
| 実行使用メモリ | 7,240 KB | 
| 最終ジャッジ日時 | 2024-09-17 06:26:01 | 
| 合計ジャッジ時間 | 2,512 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 33 | 
ソースコード
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
typedef int32_t i32;
typedef int64_t i64;
typedef struct cake {
  i32 a, b, c;
} node;
int cmp_node (const void *a, const void *b) {
  node *p = (node *)a;
  node *q = (node *)b;
  if (p->a != q->a) return p->a < q->a ? -1 : 1;
  return p->b > q->b ? -1 : 1;
}
int cmp_int (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}
i32 to_index (i32 *z, i32 n, i32 v) {
  i32 l = 0;
  i32 r = n;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    if (z[m] <= v) {
      l = m;
    } else {
      r = m;
    }
  }
  return l;
}
i64 max (i64 a, i64 b) {
  return a > b ? a : b;
}
void update (i64 *bit, i32 x, i64 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n && bit[i] < v; i += i & -i) {
    bit[i] = v;
  }
}
i64 calc_max (i64 *bit, i32 x) {
  i64 res = 0;
  for (i32 i = x; i > 0; i -= i & -i) {
    res = max (res, bit[i]);
  }
  return res;
}
void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  node *p = (node *) calloc (n, sizeof (node));
  i32 *z = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    i32 a, b, c;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &c);
    p[i] = (node) {a, b, c};
    z[i] = b;
  }
  qsort (p, n, sizeof (node), cmp_node);
  qsort (z, n, sizeof (i32), cmp_int);
  i32 len = 1;
  for (i32 i = 1; i < n; ++i) {
    if (z[i] == z[len - 1]) continue;
    z[len++] = z[i];
  }
  i64 *bit = (i64 *) calloc (len + 1, sizeof (i64));
  bit[0] = len;
  for (i32 i = 0; i < n; ++i) {
    i32 k = to_index (z, len, p[i].b) + 1;
    i64 v = calc_max (bit, k - 1) + p[i].c;
    update (bit, k, v);
  }
  printf ("%" PRIi64 "\n", calc_max (bit, len));
}
int main (void) {
  run();
  return 0;
}
            
            
            
        