Submission #25005

#TimeUsernameProblemLanguageResultExecution timeMemory
25005bugmenot111Hindeks (COCI17_hindeks)C11
50 / 50
103 ms8928 KiB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MAXN 1000100
int v[MAXN];
int score[MAXN];
int n;
bool check(int h) {
	int s = 0;
	for(int i = 0; i < n; i++) if(score[i] >= h) s++;
	return s >= h;
}
int cmp(const int* a, const int* b) {
	bool c1 = check(b - v), c2 = check(b - v + 1);
	return c1 ? (c2 ? 1 : 0) : -1;
}
int main(void) {
    int j = 15;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &score[i]);
	int* ans = bsearch(&j, v, MAXN, sizeof(int), cmp);
	printf("%d\n", ans - v);
	return 0;
}

Compilation message (stderr)

hindeks.c: In function 'main':
hindeks.c:21:47: warning: passing argument 5 of 'bsearch' from incompatible pointer type [-Wincompatible-pointer-types]
  int* ans = bsearch(&j, v, MAXN, sizeof(int), cmp);
                                               ^
In file included from /usr/include/stdlib.h:759:0,
                 from hindeks.c:2:
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:20:1: note: expected '__compar_fn_t {aka int (*)(const void *, const void *)}' but argument is of type 'int (*)(const int *, const int *)'
 bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
 ^
hindeks.c:22:9: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
  printf("%d\n", ans - v);
         ^
hindeks.c:19:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ^
hindeks.c:20:29: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < n; i++) scanf("%d", &score[i]);
                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...