結果

問題 No.2235 Line Up Colored Balls
ユーザー umezo
提出日時 2023-03-03 22:27:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 194,944 KB
最終ジャッジ日時 2025-02-11 03:09:57
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;
ll modpow(ll x,ll n){
  x%=MOD;
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<ll> X(n);
  rep(i,n) cin>>X[i];
  ll sum=0,sum1=0;
  rep(i,n){
    sum+=X[i];
    sum1=(sum1+X[i]*X[i]%MOD)%MOD;
  }
  cout<<(sum+1-sum1*modpow(sum,MOD-2)%MOD+MOD)%MOD<<endl;

  return 0;
}
0