結果
問題 |
No.777 再帰的ケーキ
|
ユーザー |
|
提出日時 | 2018-12-24 17:51:18 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 1,156 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 38,456 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-25 11:01:49 |
合計ジャッジ時間 | 2,629 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> #include <algorithm> struct P { int a, b, c; }; int n; struct P a[200000]; long long bit[200001]; long long max(long long x, long long y) { return x > y ? x : y; } bool cmp(struct P x, struct P y) { if (x.a != y.a) return x.a < y.a; return x.b > y.b; } bool cmpb(struct P x, struct P y) { return x.b < y.b; } void update(int k, long long v) { for (int i = k + 1; i <= 200000 && bit[i] < v; i += i & -i) { bit[i] = v; } } long long query(int k) { long long res = 0; for (int i = k; i > 0; i -= i & -i) { res = max(res, bit[i]); } return res; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].c); } std::sort(a, a + n, cmpb); { int k = -1; int p = -1; for (int i = 0; i < n; i++) { k += p != a[i].b; p = a[i].b; a[i].b = k; } } std::sort(a, a + n, cmp); for (int i = 0; i < n; i++) { update(a[i].b, query(a[i].b) + a[i].c); } printf("%lld\n", query(200000)); }