結果

問題 No.797 Noelちゃんとピラミッド
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-03-17 22:42:06
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,100 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 106,348 KB
実行使用メモリ 16,712 KB
最終ジャッジ日時 2023-09-03 23:50:43
合計ジャッジ時間 4,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
11,352 KB
testcase_01 AC 13 ms
11,496 KB
testcase_02 AC 13 ms
11,660 KB
testcase_03 AC 32 ms
15,456 KB
testcase_04 AC 32 ms
15,836 KB
testcase_05 AC 32 ms
15,184 KB
testcase_06 AC 32 ms
14,756 KB
testcase_07 AC 33 ms
13,892 KB
testcase_08 AC 32 ms
13,792 KB
testcase_09 AC 32 ms
15,816 KB
testcase_10 AC 33 ms
16,400 KB
testcase_11 AC 33 ms
16,096 KB
testcase_12 AC 31 ms
14,036 KB
testcase_13 AC 32 ms
14,788 KB
testcase_14 AC 33 ms
16,072 KB
testcase_15 AC 32 ms
13,768 KB
testcase_16 AC 31 ms
13,848 KB
testcase_17 AC 32 ms
13,752 KB
testcase_18 AC 33 ms
16,284 KB
testcase_19 AC 33 ms
15,812 KB
testcase_20 AC 31 ms
14,624 KB
testcase_21 AC 32 ms
16,712 KB
testcase_22 AC 33 ms
16,244 KB
testcase_23 AC 28 ms
15,320 KB
testcase_24 AC 17 ms
13,008 KB
testcase_25 AC 25 ms
13,832 KB
testcase_26 AC 24 ms
13,628 KB
testcase_27 AC 32 ms
16,108 KB
testcase_28 AC 29 ms
14,284 KB
testcase_29 AC 17 ms
11,164 KB
testcase_30 AC 17 ms
12,316 KB
testcase_31 AC 28 ms
15,636 KB
testcase_32 AC 20 ms
12,400 KB
testcase_33 AC 26 ms
14,320 KB
testcase_34 AC 21 ms
13,208 KB
testcase_35 AC 34 ms
16,200 KB
testcase_36 AC 15 ms
11,160 KB
testcase_37 AC 28 ms
13,860 KB
testcase_38 AC 32 ms
15,248 KB
testcase_39 AC 25 ms
14,476 KB
testcase_40 AC 15 ms
12,700 KB
testcase_41 AC 18 ms
12,656 KB
testcase_42 AC 24 ms
14,320 KB
testcase_43 AC 13 ms
11,472 KB
testcase_44 AC 13 ms
11,204 KB
testcase_45 AC 15 ms
12,308 KB
testcase_46 AC 14 ms
11,128 KB
testcase_47 AC 15 ms
11,312 KB
testcase_48 AC 13 ms
11,856 KB
testcase_49 AC 12 ms
11,088 KB
testcase_50 AC 15 ms
11,976 KB
testcase_51 AC 14 ms
11,512 KB
testcase_52 AC 15 ms
12,016 KB
testcase_53 AC 13 ms
11,296 KB
testcase_54 AC 14 ms
11,720 KB
testcase_55 AC 14 ms
11,888 KB
testcase_56 AC 12 ms
11,312 KB
testcase_57 AC 14 ms
11,764 KB
testcase_58 AC 14 ms
11,928 KB
testcase_59 AC 14 ms
11,848 KB
testcase_60 AC 14 ms
11,124 KB
testcase_61 AC 15 ms
12,032 KB
testcase_62 AC 14 ms
12,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum MO = 10L^^9 + 7;
enum LIM = 3 * 10^^5;

long[] inv, fac, invFac;
void prepare() {
  inv = new long[LIM];
  fac = new long[LIM];
  invFac = new long[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = MO - ((MO / i) * inv[cast(size_t)(MO % i)]) % MO;
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = (fac[i - 1] * i) % MO;
    invFac[i] = (invFac[i - 1] * inv[i]) % MO;
  }
}
long binom(long n, long k) {
  if (0 <= k && k <= n) {
    assert(n < LIM);
    return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] % MO * invFac[cast(size_t)(n - k)] % MO;
  } else {
    return 0;
  }
}

int N;
long[] A;

void main() {
  prepare();
  
  try {
    for (; ; ) {
      N = readInt();
      A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      
      long ans;
      foreach (i; 0 .. N) {
        ans += binom(N - 1, i) * A[i];
        ans %= MO;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0