結果
問題 |
No.2210 equence Squence Seuence
|
ユーザー |
![]() |
提出日時 | 2023-03-09 23:49:17 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 30,848 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-09-18 03:07:03 |
合計ジャッジ時間 | 2,554 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <stdio.h> #include <stdlib.h> int pos[199999] = {}; int s[199999] = {}; int cmp_idx (const void *ap, const void *bp) { int a = *(int *)ap; int b = *(int *)bp; if (a == b) { return 0; } if (a > b) { return (-1)*cmp_idx(bp, ap); } if (pos[a] >= b) { return 0; } return s[pos[a]]; } int main () { int n = 0; int k = 0; int a[200000] = {}; int res = 0; int ans[200000] = {}; int b[200000] = {}; res = scanf("%d", &n); res = scanf("%d", &k); for (int i = 0; i < n; i++) { res = scanf("%d", a+i); ans[i] = i; } for (int i = 0; i < n-1; i++) { if (a[i] < a[i+1]) { s[i] = 1; } else if (a[i] > a[i+1]) { s[i] = -1; } } if (s[n-2] == 0) { pos[n-2] = n-1; } else { pos[n-2] = n-2; } for (int i = n-3; i >= 0; i--) { if (s[i] == 0) { pos[i] = pos[i+1]; } else { pos[i] = i; } } qsort(ans, n, sizeof(int), cmp_idx); for (int i = 0; i < ans[k-1]; i++) { b[i] = a[i]; } for (int i = ans[k-1]; i < n-1; i++) { b[i] = a[i+1]; } printf("%d", b[0]); for (int i = 1; i < n-1; i++) { printf(" %d", b[i]); } printf("\n"); return 0; }