結果
問題 |
No.2235 Line Up Colored Balls
|
ユーザー |
|
提出日時 | 2023-03-03 22:48:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,061 bytes |
コンパイル時間 | 1,390 ms |
コンパイル使用メモリ | 168,876 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-18 01:12:34 |
合計ジャッジ時間 | 3,188 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define drep(i, cc, n) for (int i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; ll pow_mod(ll x, ll n, ll mod){ ll ret = 1; while(n > 0){ if(n & 1) ret = (ret*x)%mod; x = x*x%mod; n >>=1; } return ret; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> x(n); rep(i, n) cin >> x[i]; ll sum = 0; rep(i, n) sum += x[i]; ll ans = 0; ll mul = 0; for(ll i=n-1; i>=0; i--){ ans = ans + (x[i] * mul)%MOD; mul = (mul + x[i]) % MOD; } ans = ans*2 % MOD; ans = ans * pow_mod(sum, MOD-2, MOD) % MOD * pow_mod(sum-1, MOD-2, MOD) % MOD; ans = ans * (sum-1) % MOD; ans = (ans + 1)%MOD; cout << ans << endl; }