You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1012 B
45 lines
1012 B
#include <iostream>
|
|
|
|
// you can use includes, for example:
|
|
// #include <algorithm>
|
|
#include <bitset>
|
|
#include <vector>
|
|
#include <limits>
|
|
|
|
constexpr size_t N_MAX_ELEMS = 1000000;
|
|
|
|
// you can write to stdout for debugging purposes, e.g.
|
|
// cout << "this is a debug message" << endl;
|
|
|
|
int solution(std::vector<int> A) {
|
|
|
|
std::vector<uint64_t> ref(N_MAX_ELEMS/sizeof(uint64_t), 0);
|
|
|
|
for (auto elem : A) {
|
|
if (elem <= 0) {
|
|
continue;
|
|
}
|
|
ref[elem/8] |= (1 << (elem%8));
|
|
}
|
|
|
|
for (size_t i = 0; i < ref.size(); i++) {
|
|
if (ref[i] != std::numeric_limits<uint64_t>::max()) {
|
|
for (size_t j = 0; j < sizeof(uint64_t); j++) {
|
|
if (i == 0 && j == 0) {
|
|
continue;
|
|
}
|
|
if ((ref[i]&(1 << j))==0) {
|
|
return (i*8+j);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return N_MAX_ELEMS+1;
|
|
}
|
|
|
|
|
|
int main() {
|
|
std::cout << solution({1,3,4,5,1,6}) << std::endl;
|
|
return 0;
|
|
}
|
|
|