이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 500000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int eval(int *aa, int *bb, int n, long long c) {
int i, j, k;
i = 0;
while (c > n - 1 - i)
c -= n - 1 - i++;
for (j = 0; j < i; j++)
bb[n - 1 - j] = aa[j];
for (j = 0; j < c; j++)
bb[j] = aa[i + 1 + j];
bb[c] = aa[i];
for (j = c + 1; j < n - i; j++)
bb[j] = aa[i + j];
k = 0;
for (i = n - 1; i >= 0; i--)
if (k < bb[i])
k++;
return k;
}
int main() {
static int aa[N], bb[N];
int n, k, i, lower, upper;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
sort(aa, 0, n);
lower = 0, upper = (long long) n * (n - 1) / 2 + 1;
while (upper - lower > 1) {
long long c = (lower + upper) / 2;
if (eval(aa, bb, n, c) <= k)
lower = c;
else
upper = c;
}
if (eval(aa, bb, n, lower) != k)
printf("-1\n");
else {
for (i = 0; i < n; i++)
printf("%d ", bb[i]);
printf("\n");
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
karte.c: In function 'main':
karte.c:54:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
karte.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |