結果
問題 | No.1687 What the Heck? |
ユーザー |
👑 |
提出日時 | 2021-09-12 14:10:20 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 995 ms |
コンパイル使用メモリ | 29,056 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 09:52:25 |
合計ジャッジ時間 | 1,761 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <stdio.h> typedef struct { int key, id; } data; typedef struct { data obj[200001]; int size; } max_heap; void push(max_heap* h, data x) { int i = ++(h->size), j = i >> 1; data tmp; h->obj[i] = x; while (j > 0) { if (h->obj[i].key > h->obj[j].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j >>= 1; } else break; } } data pop(max_heap* h) { int i = 1, j = 2; data output = h->obj[1], tmp; h->obj[1] = h->obj[(h->size)--]; while (j <= h->size) { if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1; if (h->obj[j].key > h->obj[i].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j <<= 1; } else break; } return output; } void chmax(long long* a, long long b) { if (*a < b) *a = b; } int main() { int i, N; data d; max_heap h; h.size = 0; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d", &(d.key)); d.id = i; push(&h, d); } long long ans = 0, tmp = (long long)N * (N + 1) / 2; while (h.size > 0) { d = pop(&h); chmax(&ans, tmp - d.id * 2); tmp -= d.id; } printf("%lld\n", ans); fflush(stdout); return 0; }