結果
問題 | No.2235 Line Up Colored Balls |
ユーザー |
![]() |
提出日時 | 2023-05-05 17:46:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,552 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 42,828 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-23 02:31:32 |
合計ジャッジ時間 | 3,076 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 55 |
ソースコード
/* -*- coding: utf-8 -*-** 2235.cc: No.2235 Line Up Colored Balls - yukicoder*/#include<cstdio>#include<algorithm>using namespace std;/* constant */const int MAX_N = 100000;const int MOD = 1000000007;/* typedef */template<const int MOD>struct MI {int v;MI(): v() {}MI(int _v): v(_v % MOD) {}MI(long long _v): v(_v % MOD) {}MI operator+(const MI m) const { return MI(v + m.v); }MI operator-(const MI m) const { return MI(v + MOD - m.v); }MI operator*(const MI m) const { return MI((long long)v * m.v); }MI &operator+=(const MI m) { return (*this = *this + m); }MI &operator-=(const MI m) { return (*this = *this - m); }MI &operator*=(const MI m) { return (*this = *this * m); }bool operator==(const MI m) const { return v == m.v; }bool operator!=(const MI m) const { return v != m.v; }MI pow(int n) const { // a^n % MODMI pm = 1, a = *this;while (n > 0) {if (n & 1) pm *= a;a *= a;n >>= 1;}return pm;}MI inv() const { return pow(MOD - 2); }MI operator/(const MI m) const { return *this * m.inv(); }MI &operator/=(const MI m) { return (*this = *this / m); }};typedef MI<MOD> mi;/* global variables */int xs[MAX_N];/* subroutines *//* main */int main() {int n;scanf("%d", &n);for (int i = 0; i < n; i++) scanf("%d", xs + i);mi sum = 0, sum2 = 0;for (int i = 0; i < n; i++) {sum += xs[i];sum2 += mi(xs[i]) * xs[i];}mi v = (sum * sum - sum2) / sum + 1;printf("%d\n", v.v);return 0;}