結果
問題 | No.1102 Remnants |
ユーザー | Haar |
提出日時 | 2020-07-04 09:10:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 950 ms / 2,000 ms |
コード長 | 4,400 bytes |
コンパイル時間 | 2,115 ms |
コンパイル使用メモリ | 207,772 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-09-17 16:05:38 |
合計ジャッジ時間 | 11,995 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 919 ms
6,940 KB |
testcase_03 | AC | 886 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 20 ms
6,944 KB |
testcase_06 | AC | 7 ms
6,940 KB |
testcase_07 | AC | 950 ms
7,168 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 598 ms
6,940 KB |
testcase_11 | AC | 257 ms
6,940 KB |
testcase_12 | AC | 431 ms
6,948 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 14 ms
6,940 KB |
testcase_15 | AC | 11 ms
6,944 KB |
testcase_16 | AC | 27 ms
6,940 KB |
testcase_17 | AC | 26 ms
6,944 KB |
testcase_18 | AC | 29 ms
6,940 KB |
testcase_19 | AC | 11 ms
6,940 KB |
testcase_20 | AC | 310 ms
6,940 KB |
testcase_21 | AC | 768 ms
6,944 KB |
testcase_22 | AC | 880 ms
6,944 KB |
testcase_23 | AC | 716 ms
6,940 KB |
testcase_24 | AC | 524 ms
6,940 KB |
testcase_25 | AC | 420 ms
6,940 KB |
testcase_26 | AC | 46 ms
6,940 KB |
testcase_27 | AC | 685 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #ifdef DEBUG #include <Mylib/Debug/debug.cpp> #else #define dump(...) #endif /** * @title Modint * @docs mint.md */ template <uint32_t M> class ModInt{ public: constexpr static uint32_t MOD = M; uint64_t val; constexpr ModInt(): val(0){} constexpr ModInt(int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);} inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);} inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);} inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);} inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;} inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;} inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;} inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;} inline constexpr bool operator==(const ModInt &a) const {return val == a.val;} inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;} inline constexpr auto& operator++(){*this += 1; return *this;} inline constexpr auto& operator--(){*this -= 1; return *this;} inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;} inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;} inline constexpr static ModInt power(int64_t n, int64_t p){ if(p < 0) return power(n, -p).inv(); int64_t ret = 1, e = n % M; for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M; return ret; } inline constexpr static ModInt inv(int64_t a){ int64_t b = M, u = 1, v = 0; while(b){ int64_t t = a / b; a -= t * b; std::swap(a,b); u -= t * v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);} inline constexpr auto power(int64_t p) const {return power(val, p);} inline constexpr auto inv() const {return inv(val);} friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);} friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;} friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;} friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;} friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;} friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;} friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;} template <int N> inline static auto div(){ static auto value = inv(N); return value; } explicit operator int32_t() const noexcept {return val;} explicit operator int64_t() const noexcept {return val;} }; using mint = ModInt<1000000007>; template <typename T> struct BigCombination{ T kfinv; std::vector<T> f, finv; int l; BigCombination(int K, int l, int r): l(l){ const int len = r - l + 1; kfinv = 1; for(int i = 1; i <= K; ++i) kfinv *= i; kfinv = kfinv.inv(); f.resize(len); finv.resize(len); f[0] = 1; for(int i = 1; i <= l; ++i) f[0] *= i; for(int i = l + 1; i <= r; ++i) f[i - l] = f[i - l - 1] * i; finv.back() = 1; for(int i = 1; i <= r - K; ++i) finv.back() *= i; finv.back() = finv.back().inv(); for(int i = r - K - 1; i >= l - K; --i) finv[i - (l - K)] = finv[i - (l - K) + 1] * (i + 1); } T operator[](int n) const {return kfinv * f[n - l] * finv[n - l];} }; int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); int N, K; while(std::cin >> N >> K){ std::vector<int> A(N); for(int i = 0; i < N; ++i) std::cin >> A[i]; BigCombination<mint> bc(K, K, K + N); mint ans = 0; for(int i = 0; i < N; ++i){ ans += bc[K + i] * bc[K + N - i - 1] * A[i]; } std::cout << ans << "\n"; } return 0; }