結果

問題 No.2210 equence Squence Seuence
ユーザー 👑 chro_96chro_96
提出日時 2023-03-09 23:49:17
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 30,656 KB
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-10-18 06:31:49
合計ジャッジ時間 4,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 14 ms
4,744 KB
testcase_04 AC 16 ms
4,744 KB
testcase_05 AC 23 ms
5,008 KB
testcase_06 AC 21 ms
4,820 KB
testcase_07 AC 50 ms
6,064 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 63 ms
6,328 KB
testcase_14 AC 62 ms
6,328 KB
testcase_15 AC 63 ms
6,328 KB
testcase_16 AC 63 ms
6,328 KB
testcase_17 AC 62 ms
6,328 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 43 ms
5,168 KB
testcase_24 AC 33 ms
4,800 KB
testcase_25 AC 39 ms
4,980 KB
testcase_26 AC 51 ms
5,308 KB
testcase_27 AC 16 ms
4,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0