結果
問題 | No.1081 和の和 |
ユーザー |
![]() |
提出日時 | 2020-06-19 22:29:22 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 4,570 bytes |
コンパイル時間 | 2,880 ms |
コンパイル使用メモリ | 112,432 KB |
最終ジャッジ日時 | 2025-01-11 07:03:16 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/char_traits.h:46, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/ios:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/iostream:39, from main.cpp:2: In function 'constexpr void std::_Construct(_Tp*, _Args&& ...) [with _Tp = modular<1000000007>; _Args = {modular<1000000007>&}]', inlined from 'constexpr _ForwardIterator std::__do_uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = modular<1000000007>*; _ForwardIterator = modular<1000000007>*]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_uninitialized.h:120:21, inlined from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = modular<1000000007>*; _ForwardIterator = modular<1000000007>*; bool _TrivialValueTypes = false]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_uninitialized.h:137:32, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = modular<1000000007>*; _ForwardIterator = modular<1000000007>*]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_uninitialized.h:185:15, inlined from 'constexpr _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = modular<1000000007>*; _ForwardIterator = modular<1000000007>*; _Tp = modular<1000000007>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_uninitialized.h:372:37, inlined from 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _All
ソースコード
#include <iostream> #include <algorithm> #include <utility> #include <numeric> #include <vector> #include <array> template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } struct range { using itr = int64_t; struct iterator { itr i; constexpr iterator(itr i_) noexcept : i(i_) { } constexpr void operator ++ () noexcept { ++i; } constexpr itr operator * () const noexcept { return i; } constexpr bool operator != (iterator x) const noexcept { return i != x.i; } }; const iterator l, r; constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { } constexpr iterator begin() const noexcept { return l; } constexpr iterator end() const noexcept { return r; } }; struct revrange { using itr = int64_t; struct iterator { itr i; constexpr iterator(itr i_) noexcept : i(i_) { } constexpr void operator ++ () noexcept { --i; } constexpr itr operator * () const noexcept { return i; } constexpr bool operator != (iterator x) const noexcept { return i != x.i; } }; const iterator l, r; constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { } constexpr iterator begin() const noexcept { return r; } constexpr iterator end() const noexcept { return l; } }; template <uint32_t Modulus> class modular { public: using value_type = uint32_t; using max_type = uint64_t; static constexpr value_type mod = Modulus; static constexpr value_type get_mod() { return mod; } static_assert(mod >= 2, "invalid mod :: smaller than 2"); static_assert(mod < (value_type(1) << 31), "invalid mod :: over 2^31"); template <class T> static constexpr value_type normalize(T value_) { if (value_ < 0) { value_ = -value_; value_ %= mod; if (value_ == 0) return 0; return mod - value_; } return value_ % mod; } private: value_type value; public: constexpr modular(): value(0) { } template <class T> explicit constexpr modular(T value_): value(normalize(value_)) { } template <class T> explicit constexpr operator T() { return static_cast<T>(value); } constexpr value_type get() const { return value; } constexpr modular operator - () const { return modular(mod - value); } constexpr modular operator ~ () const { return inverse(); } constexpr value_type &extract() { return value; } constexpr modular inverse() const { return power(mod - 2); } constexpr modular power(max_type exp) const { modular res(1), mult(*this); while (exp > 0) { if (exp & 1) res *= mult; mult *= mult; exp >>= 1; } return res; } constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; } constexpr modular& operator += (const modular &rhs) { if ((value += rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; } constexpr modular& operator -= (const modular &rhs) { if ((value += mod - rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; } constexpr modular& operator *= (const modular &rhs) { value = (max_type) value * rhs.value % mod; return *this; } constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; } constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); } constexpr bool zero() const { return value == 0; } constexpr bool operator == (const modular &rhs) const { return value == rhs.value; } constexpr bool operator != (const modular &rhs) const { return value != rhs.value; } friend std::ostream& operator << (std::ostream &stream, const modular &rhs) { return stream << rhs.value; } }; using m32 = modular<1000000007>; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; int main() { size_t N; std::cin >> N; std::vector<m32> A(N); for (auto &x: A) { std::cin >> x.extract(); } for (auto query: range(1, N)) { std::vector<m32> next(A.size() - 1); for (auto i: range(1, A.size())) { next[i - 1] = A[i - 1] + A[i]; } A = next; } std::cout << A.front() << '\n'; return 0; }