結果
| 問題 |
No.1081 和の和
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2020-06-23 10:51:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 2,106 bytes |
| コンパイル時間 | 1,025 ms |
| コンパイル使用メモリ | 114,924 KB |
| 実行使用メモリ | 28,956 KB |
| 最終ジャッジ日時 | 2024-07-03 19:11:00 |
| 合計ジャッジ時間 | 1,808 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq;
using System.Collections.Generic;
using System;
class Modular
{
private const int M = 1000000007;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a)
{
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b)
{
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b)
{
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b)
{
return a.value * b.value;
}
private static Modular Pow(Modular a, int n)
{
switch (n)
{
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b)
{
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n)
{
for (int i = facs.Count; i <= n; ++i)
{
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r)
{
return (n < r) ? 0
: (n == r) ? 1
: Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a)
{
return (int)a.value;
}
}
public class Hello
{
public static int MOD = 1000000007;
static void Main()
{
var n = int.Parse(Console.ReadLine().Trim());
string[] line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, long.Parse);
getAns(n, a);
}
static void getAns(int n, long[] a)
{
var ans = 0L;
for (int i = 0; i < n; i++)
{
ans += (a[i] * (long)Modular.Ncr(n - 1, i)) % MOD;
}
Console.WriteLine(ans % MOD);
}
}
bluemegane