結果

問題 No.1102 Remnants
ユーザー eSeF
提出日時 2020-07-03 16:25:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 1,949 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 114,760 KB
実行使用メモリ 53,432 KB
最終ジャッジ日時 2024-09-16 17:07:41
合計ジャッジ時間 6,884 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
class AC
{
    static void Main()
    {
        var (N, K) = Csin.Input<int, long>();
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
        const int MOD = (int)1e9 + 7;
        long modpow(long x, int n)
        {
            if (n == 0) return 1L;
            return n % 2 == 0 ? modpow((x * x) % MOD, n / 2) % MOD : (x * modpow(x, n - 1)) % MOD;
        }
        var comb = new long[N];
        comb[0] = 1;
        for (var i = 1; i < N; i++) comb[i] = ((comb[i - 1] * (K + i)) % MOD * modpow(i, MOD - 2)) % MOD;
        long ans = 0;
        for (var i = 0; i < N; i++)
        {
            ans += ((comb[i] * comb[N - 1 - i]) % MOD * A[i]) % MOD;
            ans %= MOD;
        }
        Console.WriteLine(ans);
    }
}
static class Csin
{
    public static string[] StrArray() => Console.ReadLine().Split();
    public static string[] StrArray(char separator) => Console.ReadLine().Split(separator);

    private static T Conv<T>(string value) => (T)Convert.ChangeType(value, typeof(T));
    public static (T, U) ReadTuple<T, U>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]));
    public static (T, U, V) ReadTuple<T, U, V>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]));
    public static (T, U, V, W) ReadTuple<T, U, V, W>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]));
    public static (T, U, V, W, X) ReadTuple<T, U, V, W, X>(string[] input) => (Conv<T>(input[0]), Conv<U>(input[1]), Conv<V>(input[2]), Conv<W>(input[3]), Conv<X>(input[4]));

    public static (T, U) Input<T, U>() => ReadTuple<T, U>(StrArray());
    public static (T, U, V) Input<T, U, V>() => ReadTuple<T, U, V>(StrArray());
    public static (T, U, V, W) Input<T, U, V, W>() => ReadTuple<T, U, V, W>(StrArray());
    public static (T, U, V, W, X) Input<T, U, V, W, X>() => ReadTuple<T, U, V, W, X>(StrArray());
}
0