結果
問題 | No.1102 Remnants |
ユーザー | rokahikou1 |
提出日時 | 2020-07-31 03:03:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 312 ms / 2,000 ms |
コード長 | 3,410 bytes |
コンパイル時間 | 874 ms |
コンパイル使用メモリ | 100,532 KB |
実行使用メモリ | 32,560 KB |
最終ジャッジ日時 | 2023-09-18 15:43:17 |
合計ジャッジ時間 | 4,614 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 36 ms
4,376 KB |
testcase_06 | AC | 12 ms
4,376 KB |
testcase_07 | AC | 312 ms
32,560 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 4 ms
4,376 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 7 ms
4,524 KB |
testcase_12 | AC | 11 ms
4,772 KB |
testcase_13 | AC | 4 ms
4,376 KB |
testcase_14 | AC | 27 ms
4,376 KB |
testcase_15 | AC | 21 ms
4,376 KB |
testcase_16 | AC | 53 ms
4,496 KB |
testcase_17 | AC | 246 ms
28,720 KB |
testcase_18 | AC | 267 ms
28,724 KB |
testcase_19 | AC | 85 ms
11,816 KB |
testcase_20 | AC | 24 ms
5,816 KB |
testcase_21 | AC | 155 ms
18,300 KB |
testcase_22 | AC | 226 ms
24,900 KB |
testcase_23 | AC | 171 ms
20,212 KB |
testcase_24 | AC | 120 ms
14,880 KB |
testcase_25 | AC | 273 ms
29,180 KB |
testcase_26 | AC | 14 ms
4,836 KB |
testcase_27 | AC | 65 ms
9,864 KB |
ソースコード
#include <algorithm> #include <cmath> #include <cstdint> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template <uint_fast64_t MOD> class ModInt { using u64 = uint_fast64_t; public: u64 val; ModInt(const u64 x = 0) : val(x % MOD) {} constexpr u64 &value() { return val; } constexpr ModInt operator-() { return val ? MOD - val : 0; } constexpr ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; } constexpr ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; } constexpr ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; } constexpr ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; } constexpr ModInt &operator+=(const ModInt &rhs) { val += rhs.val; if(val >= MOD) { val -= MOD; } return *this; } constexpr ModInt &operator-=(const ModInt &rhs) { if(val < rhs.val) { val += MOD; } val -= rhs.val; return *this; } constexpr ModInt &operator*=(const ModInt &rhs) { val = val * rhs.val % MOD; return *this; } constexpr ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inv(); return *this; } constexpr bool operator==(const ModInt &rhs) { return this->a == rhs.a; } constexpr bool operator!=(const ModInt &rhs) { return this->a != rhs.a; } friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) { return os << x.val; } friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) { return is >> x.val; } constexpr ModInt inv() const { return ModInt(*this).pow(MOD - 2); } constexpr ModInt pow(ll e) const { u64 x = 1, p = val; while(e > 0) { if(e % 2 == 0) { p = (p * p) % MOD; e /= 2; } else { x = (x * p) % MOD; e--; } } return ModInt(x); } }; using mint = ModInt<MOD>; //二項係数 O(k) // nとkのどちらかが変化するとき、O((n or k) + 変化量)(???)ですべて求められる template <class T> T nCk(ll n, ll k, map<pair<ll, ll>, T> &mp) { auto key = MP(n, k); if(mp.count(key)) return mp[key]; if(k == 0 || k == n) { T ret = 1; return ret; } if(k == 1 || k == n - 1) { T ret = n; return ret; } // return mp[key] = nCk(n, k - 1, mp) * T(n - k + 1) / T(k); return mp[key] = nCk(n - 1, k, mp) * n / (n - k); } int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; mint res = 0; map<pll, mint> mp; rep(i, N) { res += nCk<mint>(i + K, K, mp) * nCk<mint>(N - i + K - 1, K, mp) * A[i]; } cout << res << endl; return 0; }