結果
問題 | No.1687 What the Heck? |
ユーザー | 👑 ygussany |
提出日時 | 2021-09-12 14:10:20 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 1,243 ms |
コンパイル使用メモリ | 28,876 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-18 20:27:08 |
合計ジャッジ時間 | 2,761 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 0 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 0 ms
4,376 KB |
testcase_07 | AC | 19 ms
4,380 KB |
testcase_08 | AC | 27 ms
4,380 KB |
testcase_09 | AC | 19 ms
4,376 KB |
testcase_10 | AC | 12 ms
4,380 KB |
testcase_11 | AC | 13 ms
4,376 KB |
testcase_12 | AC | 56 ms
4,376 KB |
testcase_13 | AC | 56 ms
4,376 KB |
testcase_14 | AC | 57 ms
4,376 KB |
testcase_15 | AC | 56 ms
4,376 KB |
testcase_16 | AC | 57 ms
4,376 KB |
testcase_17 | AC | 4 ms
4,376 KB |
testcase_18 | AC | 56 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,380 KB |
ソースコード
#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; }