結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | noshi91 |
提出日時 | 2019-09-20 22:52:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 6,534 bytes |
コンパイル時間 | 851 ms |
コンパイル使用メモリ | 87,300 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 16:50:48 |
合計ジャッジ時間 | 1,789 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 6 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 4 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 5 ms
5,376 KB |
testcase_18 | AC | 6 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 5 ms
5,376 KB |
testcase_23 | AC | 4 ms
5,376 KB |
testcase_24 | AC | 4 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 4 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | AC | 5 ms
5,376 KB |
testcase_30 | AC | 4 ms
5,376 KB |
testcase_31 | AC | 4 ms
5,376 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64, from main.cpp:6: In member function 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long unsigned int; _Alloc = std::allocator<long unsigned int>]', inlined from 'void n91::main_()' at main.cpp:227:24: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1143:41: warning: 'mem' may be used uninitialized [-Wmaybe-uninitialized] 1143 | return *(this->_M_impl._M_start + __n); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ main.cpp: In function 'void n91::main_()': main.cpp:215:11: note: 'mem' was declared here 215 | usize mem; | ^~~
ソースコード
//#define NDEBUG #include <cstddef> #include <cstdint> #include <iostream> #include <iterator> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast<usize>(x); } template <class T> class integral_iterator { public: using difference_type = T; using value_type = T; using pointer = const value_type*; using reference = value_type; using iterator_category = std::random_access_iterator_tag; private: using self_type = integral_iterator<value_type>; value_type i; public: constexpr integral_iterator() noexcept : i() {} explicit constexpr integral_iterator(const value_type i) noexcept : i(i) {} constexpr self_type operator++(int) noexcept { return self_type(i++); } constexpr self_type operator--(int) noexcept { return self_type(i--); } constexpr self_type operator[](const difference_type rhs) const noexcept { return self_type(i + rhs); } constexpr self_type& operator++() noexcept { ++i; return *this; } constexpr self_type& operator--() noexcept { --i; return *this; } constexpr reference operator*() const noexcept { return i; } constexpr self_type operator+(const difference_type rhs) const noexcept { return self_type(i + rhs); } constexpr self_type operator-(const difference_type rhs) const noexcept { return self_type(i - rhs); } constexpr difference_type operator-(const self_type rhs) const noexcept { return i - rhs.i; } constexpr bool operator<(const self_type rhs) const noexcept { return i < rhs.i; } constexpr bool operator<=(const self_type rhs) const noexcept { return i <= rhs.i; } constexpr bool operator>(const self_type rhs) const noexcept { return i > rhs.i; } constexpr bool operator>=(const self_type rhs) const noexcept { return i >= rhs.i; } constexpr bool operator==(const self_type rhs) const noexcept { return i == rhs.i; } constexpr bool operator!=(const self_type rhs) const noexcept { return i != rhs.i; } constexpr self_type& operator+=(const difference_type rhs) noexcept { i += rhs; return *this; } constexpr self_type& operator-=(const difference_type rhs) noexcept { i -= rhs; return *this; } }; template <class T> constexpr integral_iterator<T> make_int_itr(const T i) noexcept { return integral_iterator<T>(i); } class rep { const usize f, l; public: constexpr rep(const usize f, const usize l) noexcept : f(f), l(l) {} constexpr auto begin() const noexcept { return make_int_itr(f); } constexpr auto end() const noexcept { return make_int_itr(l); } }; class revrep { const usize f, l; public: revrep(const usize f, const usize l) noexcept : f(l), l(f) {} auto begin() const noexcept { return std::make_reverse_iterator(make_int_itr(f)); } auto end() const noexcept { return std::make_reverse_iterator(make_int_itr(l)); } }; template <class T> auto md_vec(const usize n, const T& value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T& a, const T& b) { return a < b ? b - a : a - b; } template <class T> T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 #include <cassert> #include <cstdint> #include <limits> #include <vector> namespace n91 { class eratosthenes { using field_type = std::uint_fast64_t; public: using container_type = std::vector<field_type>; using size_type = typename container_type::size_type; protected: static constexpr size_type WordSize = static_cast<size_type>(std::numeric_limits<field_type>::digits); container_type c; public: eratosthenes() noexcept : c() {} explicit eratosthenes(const size_type max) : c(max / WordSize + static_cast<size_type>(1), ~static_cast<field_type>(0)) { const size_type limit = c.size() * WordSize; c[static_cast<size_type>(0)] &= ~static_cast<field_type>(3); for (size_type i = static_cast<size_type>(2); i * i < limit; ++i) { if ((c[i / WordSize] & static_cast<field_type>(1) << i % WordSize) != static_cast<field_type>(0)) { for (size_type j = i * i; j < limit; j += i) { c[j / WordSize] &= ~(static_cast<field_type>(1) << j % WordSize); } } } } bool test(const size_type i) const noexcept { assert(i < c.size() * WordSize); return (c[i / WordSize] & static_cast<field_type>(1) << i % WordSize) != static_cast<field_type>(0); } bool operator[](const size_type i) const noexcept { assert(i < c.size() * WordSize); return (c[i / WordSize] & static_cast<field_type>(1) << i % WordSize) != static_cast<field_type>(0); } }; } // namespace n91 #include <utility> #include <vector> namespace n91 { template <class T, class F> std::vector<T> filter(const std::vector<T>& a, const F& f) { std::vector<T> ret; ret.reserve(a.size()); for (const T& e : a) { if (f(e)) { ret.push_back(e); } } ret.shrink_to_fit(); return std::move(ret); } } // namespace n91 #include <algorithm> #include <iostream> #include <set> #include <utility> namespace n91 { void main_() { const usize k = scan<usize>(); const usize n = scan<usize>(); const eratosthenes sieve(n); const auto ps = filter(std::vector<usize>(make_int_itr(k), make_int_itr(n + 1_z)), [&](const usize x) { return sieve[x]; }); std::set<usize> hs; usize r = 0_z; usize max = 0_z; usize mem; for (const auto i : rep(0_z, ps.size())) { while (r != ps.size() && !hs.count(ps[r] % 9_z)) { hs.insert(ps[r] % 9_z); ++r; } if (max <= r - i) { max = r - i; mem = i; } hs.erase(ps[i] % 9_z); } std::cout << ps[mem] << std::endl; } } // namespace n91 int main() { n91::main_(); return 0; }