結果

問題 No.2627 Unnatural Pitch
ユーザー 👑 chro_96chro_96
提出日時 2024-02-09 23:11:35
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,292 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-09 23:11:45
合計ジャッジ時間 2,768 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 70 ms
6,676 KB
testcase_05 AC 69 ms
6,676 KB
testcase_06 AC 52 ms
6,676 KB
testcase_07 AC 52 ms
6,676 KB
testcase_08 AC 58 ms
6,676 KB
testcase_09 AC 81 ms
6,676 KB
testcase_10 AC 101 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 87 ms
6,676 KB
testcase_17 WA -
testcase_18 AC 219 ms
6,676 KB
testcase_19 AC 123 ms
6,676 KB
testcase_20 AC 58 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 57 ms
6,676 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_ll (const void *ap, const void *bp) {
  long long a = *(long long *)ap;
  long long b = *(long long *)bp;
  
  if (a > b) {
    return 1;
  }
  
  if (a < b) {
    return -1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  long long k = 0LL;
  long long l = 0LL;
  long long u = 0LL;
  long long a[200000] = {};
  
  int res = 0;
  
  long long ans = 1000000000000000000LL;
  int idx = 0;
  
  long long b[200000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%lld", &k);
  res = scanf("%lld", &l);
  res = scanf("%lld", &u);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", a+i);
  }
  
  qsort(a, n, sizeof(long long), cmp_ll);
  
  for (int i = 0; i < n; i++) {
    while (idx < n && a[i]+u-l >= a[idx]) {
      idx++;
    }
    if (i == n-idx || i+1 == n-idx || i == n-idx+1) {
      long long tmp = 0LL;
      int tidx = 0;
      for (int j = 0; j < n; j++) {
        if (a[j] < a[i]) {
          tmp += 1LL+(a[i]-a[j]-1LL)/k;
        } else if (a[j] > a[i]+u-l) {
          tmp += 1LL+(a[j]-a[i]-u+l-1LL)/k;
        }
      }
      if (tmp < ans) {
        ans = tmp;
      }
      for (int j = 0; j < n; j++) {
        if (a[j] < a[i]) {
          b[j] = ((a[i]-a[j]-1LL)/k)*k+a[j];
        } else if (a[j] > a[i]+u-l) {
          b[j] = a[j]-(1LL+(a[j]-a[i]-u+l-1LL)/k)*k;
        } else {
          b[j] = a[j];
        }
      }
      qsort(b, n, sizeof(long long), cmp_ll);
      for (int j = 0; j < i; j++) {
        while (tidx < n && b[j]+u-l >= b[tidx]) {
          tidx++;
        }
        if (tmp-((long long)(i-j-n-tidx)) < ans) {
          ans = tmp-((long long)(i-j-n-tidx));
        }
      }
      for (int j = 0; j < n; j++) {
        if (a[j] < a[i]) {
          b[j] = (1LL+(a[i]-a[j]-1LL)/k)*k+a[j];
        } else if (a[j] > a[i]+u-l) {
          b[j] = a[j]-((a[j]-a[i]-u+l-1LL)/k)*k;
        } else {
          b[j] = a[j];
        }
      }
      qsort(b, n, sizeof(long long), cmp_ll);
      tidx = n-1;
      for (int j = n-1; j >= idx; j--) {
        while (tidx >= 0 && b[j]-u+l <= b[tidx]) {
          tidx--;
        }
        if (tmp-((long long)(j+1-idx-tidx-1)) < ans) {
          ans = tmp-((long long)(j+1-idx-tidx-1));
        }
      }
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}
0