// ###
// #---##
// ####-0----##
// ####--------#
// #--------#
// ##-------#
// #-------#
// #-------#
// ##--------#
// #---------# #####
// #-------##-------####### Ya katala
// #------#----------------#
// #------##-----------------#
// #------##------------------#
// #-----#---------------------#
// #-----##---------------------#
// #------##--------------------#
// #-------##-------------------#
// #--------##------------------#
// ############################ #
// || ||
// || ||
// || ||
// || ||
// ####| ####|
#include <bits/stdc++.h>
#define for0(i , v) for (int i = 0 ; i < v.size() ; i++)
#define for1(i , n) for (int i = 1 ; i <= n ; i++)
#define AIDS ios_base::sync_with_stdio(0)
#define pb push_back
#define pp pop_back
#define sz(a) a.size()
#define all(x) x.begin() , x.end()
#define F first
#define S second
#define mp make_pair
#define ld long double
#define ll long long
#define pii pair<int, int>
#define in insert
const int N = 1e6 + 3;
const ll INF = 1e18 + 100;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int dx[] = {0 , 1 , 0 , -1 , 0};
const int dy[] = {0 , 0 , 1 , 0 , -1};
const char dd[] = {' ' , 'D' , 'R' , 'U' , 'L'};
using namespace std;
int a[N];
main () {
// freopen("glasses.in", "r", stdin);
// freopen("output.out", "w", stdout);
AIDS;
int n;
cin >> n;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
int l = 0;
int r = n + 1;
while (l < r) {
int mid = (l + r) / 2;
int cnt = 0;
for (int i = 1 ; i <= n ; i++) {
if (a[i] >= mid) {
cnt++;
}
}
if (cnt > mid) {
l = mid + 1;
}
else {
r = mid;
}
}
int cnt = 0;
for (int i = 1 ; i <= n ; i++) {
if (a[i] >= l) {
cnt++;
}
}
if (cnt == l)
cout << l;
else {
cout << 0;
}
}
Compilation message
hindeks.cpp:59:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
5 |
Correct |
2 ms |
568 KB |
Output is correct |
6 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
7 |
Correct |
3 ms |
588 KB |
Output is correct |
8 |
Correct |
24 ms |
992 KB |
Output is correct |
9 |
Incorrect |
108 ms |
2528 KB |
Output isn't correct |
10 |
Correct |
34 ms |
2528 KB |
Output is correct |