結果

問題 No.1081 和の和
ユーザー RenFukatsu
提出日時 2020-06-19 21:31:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,093 bytes
コンパイル時間 2,475 ms
コンパイル使用メモリ 197,192 KB
最終ジャッジ日時 2025-01-11 05:48:23
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint
{
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint &operator+=(const mint m)
{
if((x += m.x) >= mod) x -= mod;
return *this;
}
mint &operator-=(const mint m)
{
if(x += mod - m.x >= mod) x -= mod;
return *this;
}
mint &operator*=(const mint m)
{
(x *= m.x) %= mod;
return *this;
}
mint operator+(const mint m) const
{
return mint(*this) += m;
}
mint operator-(const mint m) const
{
return mint(*this) -= m;
}
mint operator*(const mint m) const
{
return mint(*this) *= m;
}
mint pow(ll n) const
{
if(!n) return 1;
mint m = pow(n>>1);
m *= m;
if(n & 1) m *= *this;
return m;
}
mint inv() const { return pow(mod-2);}
mint &operator/=(const mint m) { return *this *= m.inv();}
mint operator/(const mint m) const { return mint(*this) /= m;}
};
istream &operator>>(istream &is, const mint &m) { return is >> m.x;}
ostream &operator<<(ostream &os, const mint &m) { return os << m.x;}
struct combination
{
vector<mint> fact, ifact;
combination(int n) : fact(n+1), ifact(n+1)
{
assert(n < mod);
fact.at(0) = 1;
for(int i=1; i<=n; i++)
{
fact.at(i) = fact.at(i-1) * i;
}
ifact.at(n) = fact.at(n).inv();
for(int i=n; i>=1; i--)
{
ifact.at(i-1) = ifact.at(i) * i;
}
}
mint operator()(int n, int k)
{
if(k < 0 || k > n) return 0;
return fact.at(n) * ifact.at(k) * ifact.at(n-k);
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for(int i=0; i<N; i++) cin >> A.at(i);
combination cmb(N-1);
mint ans = 0;
for(int i=0; i<N; i++)
{
ans += cmb(N-1, i) * A[i];
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0