結果
| 問題 |
No.2627 Unnatural Pitch
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2024-02-10 00:29:11 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,025 bytes |
| コンパイル時間 | 408 ms |
| コンパイル使用メモリ | 34,492 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-09-28 16:44:50 |
| 合計ジャッジ時間 | 4,075 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 2 |
ソースコード
#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 == 0 || a[i] != a[i-1]) && (i == n-idx || i+1 == n-idx || i == n-idx+1 || i+2 == n-idx || i == n-idx+2)) {
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));
}
}
}
}
idx = n-1;
for (int i = n-1; i >= 0; i--) {
while (idx >= 0 && a[i]-u+l <= a[idx]) {
idx--;
}
if ((i == n-1 || a[i] != a[i+1]) && (n-i-1 == idx+1 || n-i == idx+1 || n-i-1 == idx+2 || n-i-1 == idx+3 || n-i+1 == idx+1)) {
long long tmp = 0LL;
int tidx = 0;
for (int j = 0; j < n; j++) {
if (a[j] > a[i]) {
tmp += 1LL+(a[j]-a[i]-1LL)/k;
} else if (a[j] < a[i]-u+l) {
tmp += 1LL+(a[i]-u+l-a[j]-1LL)/k;
}
}
if (tmp < ans) {
ans = tmp;
}
for (int j = 0; j < n; j++) {
if (a[j] > a[i]) {
b[j] = a[j]-((a[j]-a[i]-1LL)/k)*k;
} else if (a[j] < a[i]-u+l) {
b[j] = a[j]+(1LL+(a[i]-a[j]-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 > i; j--) {
while (tidx >= 0 && b[j]-u+l <= b[tidx]) {
tidx--;
}
if (tmp-((long long)(j-i-tidx-1)) < ans) {
ans = tmp-((long long)(j-i-tidx-1));
}
}
for (int j = 0; j < n; j++) {
if (a[j] > a[i]) {
b[j] = a[j]-(1LL+(a[j]-a[i]-1LL)/k)*k;
} else if (a[j] < a[i]-u+l) {
b[j] = a[j]+((a[i]-a[j]-u+l-1LL)/k)*k;
} else {
b[j] = a[j];
}
}
qsort(b, n, sizeof(long long), cmp_ll);
tidx = 0;
for (int j = 0; j <= idx; j++) {
while (tidx < n && b[j]+u-l >= b[tidx]) {
tidx++;
}
if (tmp-((long long)(idx-j+1-n+tidx)) < ans) {
ans = tmp-((long long)(idx-j+1-n+tidx));
}
}
}
}
printf("%lld\n", ans);
return 0;
}
chro_96