結果

問題 No.1102 Remnants
ユーザー QCFiumQCFium
提出日時 2020-07-03 21:38:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 753 ms / 2,000 ms
コード長 2,995 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 6,088 KB
最終ジャッジ日時 2023-10-16 23:40:31
合計ジャッジ時間 9,744 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 567 ms
4,352 KB
testcase_03 AC 550 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 97 ms
5,700 KB
testcase_06 AC 18 ms
4,352 KB
testcase_07 AC 753 ms
6,088 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 372 ms
4,352 KB
testcase_11 AC 163 ms
4,352 KB
testcase_12 AC 276 ms
4,352 KB
testcase_13 AC 7 ms
4,352 KB
testcase_14 AC 56 ms
4,816 KB
testcase_15 AC 43 ms
4,560 KB
testcase_16 AC 111 ms
5,892 KB
testcase_17 AC 188 ms
5,764 KB
testcase_18 AC 174 ms
5,776 KB
testcase_19 AC 58 ms
4,432 KB
testcase_20 AC 207 ms
4,352 KB
testcase_21 AC 557 ms
4,956 KB
testcase_22 AC 660 ms
5,476 KB
testcase_23 AC 552 ms
5,076 KB
testcase_24 AC 401 ms
4,696 KB
testcase_25 AC 437 ms
5,816 KB
testcase_26 AC 38 ms
4,352 KB
testcase_27 AC 463 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};

template<int mod> struct MComb {
	using mint = ModInt<mod>;
	std::vector<mint> fact;
	std::vector<mint> inv;
	MComb (int n) { // O(n + log(mod))
		fact = std::vector<mint>(n + 1, 1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
		inv.resize(n + 1);
		inv[n] = fact[n] ^ (mod - 2);
		for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
	}
	mint ncr(int n, int r) {
		return fact[n] * inv[r] * inv[n - r];
	}
	mint npr(int n, int r) {
		return fact[n] * inv[n - r];
	}
	mint nhr(int n, int r) {
		assert(n + r - 1 < (int) fact.size());
		return ncr(n + r - 1, r);
	}
};

typedef ModInt<1000000007> mint;


int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (auto &i : a) i = ri();
	mint res = 0;
	mint kfact[n];
	kfact[0] = 1;
	for (int i = 1; i <= k; i++) kfact[0] *= i;
	for (int i = 1; i < n; i++) kfact[i] = kfact[i - 1] * (k + i);
	mint fact[n];
	fact[0] = 1;
	for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i;
	
	for (int i = 0; i < n; i++) {
		int left = i;
		int right = n - i - 1;
		res += kfact[left] / kfact[0] / fact[left] * kfact[right] / kfact[0] / fact[right] * a[i];
	}
	std::cout << res << std::endl;
	return 0;
}
0