답안 #25005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25005 2017-06-20T00:23:23 Z bugmenot111 Hindeks (COCI17_hindeks) C
50 / 50
103 ms 8928 KB
#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

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]);
                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8928 KB Output is correct
2 Correct 0 ms 8928 KB Output is correct
3 Correct 0 ms 8928 KB Output is correct
4 Correct 0 ms 8928 KB Output is correct
5 Correct 0 ms 8928 KB Output is correct
6 Correct 0 ms 8928 KB Output is correct
7 Correct 3 ms 8928 KB Output is correct
8 Correct 19 ms 8928 KB Output is correct
9 Correct 103 ms 8928 KB Output is correct
10 Correct 46 ms 8928 KB Output is correct