# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472985 |
2021-09-14T17:30:10 Z |
rainboy |
Karte (COCI18_karte) |
C |
|
121 ms |
7160 KB |
#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;
}
Compilation message
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 |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
7160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |