結果

問題 No.797 Noelちゃんとピラミッド
ユーザー nanaenanae
提出日時 2019-03-16 12:01:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 3,376 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 100,868 KB
実行使用メモリ 8,672 KB
最終ジャッジ日時 2023-09-03 23:43:56
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 28 ms
7,332 KB
testcase_04 AC 27 ms
7,344 KB
testcase_05 AC 28 ms
7,248 KB
testcase_06 AC 28 ms
7,068 KB
testcase_07 AC 28 ms
7,232 KB
testcase_08 AC 28 ms
7,200 KB
testcase_09 AC 28 ms
7,296 KB
testcase_10 AC 29 ms
8,636 KB
testcase_11 AC 29 ms
8,636 KB
testcase_12 AC 28 ms
7,328 KB
testcase_13 AC 28 ms
7,300 KB
testcase_14 AC 28 ms
7,156 KB
testcase_15 AC 28 ms
7,248 KB
testcase_16 AC 28 ms
7,440 KB
testcase_17 AC 28 ms
7,204 KB
testcase_18 AC 28 ms
7,232 KB
testcase_19 AC 27 ms
7,312 KB
testcase_20 AC 28 ms
7,436 KB
testcase_21 AC 28 ms
7,184 KB
testcase_22 AC 28 ms
8,636 KB
testcase_23 AC 20 ms
6,308 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 16 ms
5,860 KB
testcase_26 AC 15 ms
5,396 KB
testcase_27 AC 27 ms
7,216 KB
testcase_28 AC 25 ms
6,968 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 19 ms
6,364 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 16 ms
5,424 KB
testcase_34 AC 12 ms
5,768 KB
testcase_35 AC 28 ms
8,672 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 25 ms
7,316 KB
testcase_38 AC 26 ms
8,348 KB
testcase_39 AC 17 ms
5,956 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 16 ms
5,600 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);

    auto a = readArr!(int)();

    auto mc = ModComb(n);

    long ans;

    foreach (i ; 0 .. n) {
        ans += 1L * a[i] * mc.c(n - 1, i);
        ans %= mod;
    }

    writeln(ans);
}


struct ModComb {
    int _N;
    long[] _fact, _factinv;
    long _mod;

    this(int n, long mod = 1_000_000_007L) {
        _N = n;
        _fact = new long[](_N + 1);
        _factinv = new long[](_N + 1);
        _mod = mod;

        _fact[0] = 1;
        foreach (i ; 1 .. _N + 1) {
            _fact[i] = (_fact[i-1] * i) % mod;
        }

        _factinv[_N] = _powmod(_fact[_N], mod - 2);
        foreach_reverse (i ; 0 .. _N) {
            _factinv[i] = (_factinv[i+1] * (i+1)) % mod;
        }
    }

    long c(int n, int k) {
        return f(n) * finv(n - k) % _mod * finv(k) % _mod;
    }

    long p(int n, int r) {
        return f(n) * finv(n - r) % _mod;
    }

    long f(int n) {
        return _fact[n];
    }

    long finv(int n) {
        return _factinv[n];
    }

    long _powmod(long x, long y) {
        return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
    }
}
















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
0