#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
int kth(int k);
void say_answer(int k);
int cnt(int k);
map <int,int> mp;
void solve(int n){
if (n<=50){
mp.clear();
for (int i = 1; i <= n; i++){
int val = kth(i);
mp[val]++;
if (mp[val] > n/3){
say_answer(val);
return;
}
}
say_answer(-1);
return;
}
int r=0;
set <int> st; st.clear();
for (int i = 1; i <= n; i++){
int val = kth(rand()%n + 1);
r++;
if (r == 60) break;
if (st.find(val) != st.end())
continue;
st.insert(val);
if (cnt(val) > n/3){
say_answer(val);
return;
}
r++;
if (r == 60) break;
}
say_answer(-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
200 KB |
Output is correct |
2 |
Correct |
5 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
200 KB |
Output is correct |
2 |
Correct |
27 ms |
200 KB |
Output is correct |
3 |
Correct |
6 ms |
200 KB |
Output is correct |
4 |
Correct |
4 ms |
200 KB |
Output is correct |
5 |
Correct |
22 ms |
200 KB |
Output is correct |
6 |
Correct |
20 ms |
200 KB |
Output is correct |
7 |
Correct |
22 ms |
200 KB |
Output is correct |
8 |
Correct |
31 ms |
200 KB |
Output is correct |
9 |
Correct |
10 ms |
200 KB |
Output is correct |
10 |
Correct |
23 ms |
200 KB |
Output is correct |
11 |
Correct |
21 ms |
200 KB |
Output is correct |
12 |
Correct |
22 ms |
200 KB |
Output is correct |
13 |
Correct |
18 ms |
200 KB |
Output is correct |
14 |
Correct |
28 ms |
200 KB |
Output is correct |