main
Nikita Tokarchuk 3 years ago
parent bf4c95a897
commit 7eef5b96a0
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 6
      CMakeLists.txt
  2. 45
      main.cpp

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.21)
project(smallest_int)
set(CMAKE_CXX_STANDARD 14)
add_executable(smallest_int main.cpp)

@ -0,0 +1,45 @@
#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;
}
Loading…
Cancel
Save