Pagini recente » Cod sursa (job #226879) | Cod sursa (job #1582218) | Cod sursa (job #89863) | Cod sursa (job #1839134) | Cod sursa (job #1179114)
#include <fstream>
#include <cstdlib>
using namespace std;
const int N = 1200000;
const int NIL = 0, DELETED = -1;
template<const int Size, const int mod>
class HashTable{
int table[Size], pos, inc;
void lookup(int x){
pos = x % Size;
inc = 1 + x % mod;
while (table[pos] != x && table[pos] != NIL){
pos += inc;
if (Size <= pos) pos -= Size;
}
}
public:
int insert(int x){
lookup(x);
table[pos] = x;
return pos;
}
inline int operator[](const int x){
return table[x];
}
void erase(int x){
lookup(x);
if (table[pos] == x) table[pos] = DELETED;
}
bool find(int x){
lookup(x);
return table[pos] == x;
}
};
HashTable<1046527, 998077> H;
int frecv[N];
int main(){
int n, x;
ifstream in("elmaj.in");
in >> n;
for (int i = 1 ; i <= n ; i++){
in >> x;
frecv[ H.insert(x) ]++;
}
in.close();
ofstream out("elmaj.out");
int best = 0;
while ( best < N && frecv[best] <= n / 2 )
best++;
if (best == N)
out << "-1\n";
else
out << H[best] << ' ' << frecv[best] << '\n';
return 0;
}